I'm trying to run a Python script within my laravel application which processes a file and stores it in a specific directory. Laravel should use that processed file further.
When running a local Laravel server using php artisan serve
and call the following php code, it's not working:
I've tested the following:
$process = new Process(['python', '--version']);
$process->run();
if(!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
return $process->getOutput();
For an unknown reason, Laravel throws me a ProcessFailedException
:
The command "python --version" failed. Exit Code: 1(General error) Working directory: D:\Path\To\Project\public Output: ================ Error Output: ================ Der Befehl "python" ist entweder falsch geschrieben oder konnte nicht gefunden werden.
which means that command "python" could not be found.
I'm using a Windows 11 machine for developing and Linux server which is used for production later.
I've installed Python 3.11.4 on my Windows and when I'm typing python --version
inside terminal, it shows me the correct Python version. So I guess Python is installed correctly on my local machine.
Something else that confuses me is that when I'm providing the full path of Python (installed at D:\Python\python.exe
), it works:
$process = new Process(['D:\Python', '--version']); // Output: Python 3.11.4
Another thing is, that running shell_exec('python --version') // Output: Python 3.11.4
(instead of using symfony/process
) works as well.
It's also working on my Linux server without providing full path.
Anyone could tell me why it's not working using symfony/process
? Why it's saying python coul0d not be found and everything else works?
I'm out of ideas. Thank you.