简体   繁体   中英

'python' is not recognized as an internal or external command, operable program or batch file using PHP passthru()

I am trying to invoke my python script from php by using passthru() function. I have already done that successfuly and for development I used xampp , now at some moment I installed manually apache,php and other add-ons. I also made changes to apache conf to make my python scripts work, some of them work when i invoke them directly via ajax,but scripts like this:

<?php

passthru("python C:/Apache24/htdocs/app1/pyscripts/export_zakup.py GARČIN
2>&1",$retval);
echo $retval;

?>

give me result like: 'python' is not recognized as an internal or external command, operable program or batch file. 1

Also when i copy python C:/Apache24/htdocs/app1/pyscripts/export_zakup.py GARČIN to my cmd it works properly. I have already spent few hours trying to find out where the problem is but unsuccessfuly. Anyone knows where the problem is?

First, locate where the Python executable is by runniing which python from the command line:

$ which python
$ /usr/bin/python

Then use the full path to the executable in your PHP script:

passthru("/usr/bin/python C:/Apache24/htdocs/app1/pyscripts/export_zakup.py GARČIN
2>&1",$retval);
echo $retval;

Keep in mind that the path will be different on Windows vs. Linux based machines. For example the latest versions on Windows typically install the executable in C:\\Python27\\ , so the full path would be C:\\Python27\\python

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM