You probably have different versions of Python installed, note that in Powershell you ran directly from the folder:
c: wampx64 www python
Which is probably not a global installation of Python, in fact I don’t even think it should be in the folder www
(but this is another problem), so when you run via PHP by shell_exec
without the path, it looks for the global installation, which is configured in the variable of the operating system, calling for PATH (environment variable), so that PHP recognizes the same as you did in powershell, you can just do so:
<?php
$pypath = 'c:\wampx64\www\python\py';
$scriptpath = 'core003.py';
$output = shell_exec(escapeshellarg($pypath) . ' ' . escapeshellarg($scriptpath));
echo $output;
Extra
You don’t need to install in the folder www
, it is sufficient that the Python is in the environment variables (Environment variables), being Windows just follow the step by step:
In my case I have Python3, Composer, php and npm, in yours must be something similar, in case you will change what is with Python (which probably points to your Python 3.0.1) to the location of your most updated Python, for example:
C: wampx64 www python;C: wampx64 www python Scripts;C: php;C: Users Latitude E6410 Appdata Roaming Composer vendor bin;C: Users Latitude E6410 Appdata Roaming npm
Click on all buttons OK until you have closed all windows that opened earlier, log on to the Windows user and Log again, ready should work your most updated Python without needing to point the way.
Thanks, you saved me. !
– Luan Devecchi
@Luandevecchi just followed what is in his screenshot, which indicates that it is in the www folder and there should be more than one installation.
– Guilherme Nascimento
Yeah, I really do. Another thing, I know the contents of the PHP page in utf-8 and still keep getting symbols instead of accents, do you think it’s something related to the script in py, or did I miss? header('Content-Type: text/html; charset=utf-8');
– Luan Devecchi
@Luandevecchi these symbols come from $output or elsewhere?
– Guilherme Nascimento
They come from $output yes!
– Luan Devecchi
@Luandevecchi tries so
echo utf8_encode($output);
– Guilherme Nascimento