Home > OS >  'python' is not recognized as an internal or external command, operable program or batch f
'python' is not recognized as an internal or external command, operable program or batch f

Time:10-22

I'm running this code via PHP file.

<?php 
echo shell_exec('python C:/wamp64/www/registration/test.py 2>&1');
?>

I'm getting this error,

'python' is not recognized as an internal or external command, operable program or batch file

I have added path variable correctly and when I run python in command line starts python console. I'm not familier with python so great if someone can help. (I'm using windows 10 and wamp server)

CodePudding user response:

Try to put full path, like this:

    echo shell_exec('C:/python27/python.exe C:/wamp64/www/registration/test.py 2>&1');

Just replace it with your path

CodePudding user response:

There is 2 ways to solve this

  1. Add python path to your system $PATH, which make you can call python from any directory (including the one the shell_exec is using) then you can simply do shell_exec('python C:/wamp64/www/registration/test.py 2>&1');
  2. Use your python path in the command as @ivan-gajic mentionned shell_exec('{python_full_path}/python C:/wamp64/www/registration/test.py 2>&1');

since you said you already added python to the PATH and it's not working, it means you added it to a specific user PATH, try adding it to the system PATH which make python accessible for every user directly

  • Related