My goal is to be able to call a python script to be executed specific python version (conda virtual envinronment) from PHP.
At the moment, I can only execute it using default python versions. (2.7 amd 3.6).
So, from a php script I am call script to be executed in python3 default system version, and from this script I call another script to be executed via a anaconda virtual envinronment. So i try to use subprocess but it does not work, and I get a permission errror:
I call python 3 script (python_transfer.py) from php and then I call script (ptt.py
) from python_transfer.py
to be executed via anaconda version of python.
php file
$command = 'python3 /var/software/python_transfer.py';
exec($command,$output, $r);
ob_start();
exec($command . " 2>&1", $output);
$result = ob_get_contents();
ob_end_clean();
echo '<pre>';
print_r($output);
echo '</pre>';
python_transfer.py file:
import subprocess
output = subprocess.check_output(["/root/anaconda3/envs/10/bin/python3.6", "/var/software/ptt.py"])
ptt.py file:
print("this is a test")
output:
[0] => Traceback (most recent call last):
[1] => File "/var/software/python_transfer.py", line 32, in
[2] => output = subprocess.check_output(["/root/anaconda3/envs/10/bin/python3.6", "/var/software/ptt.py"])
[3] => File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
[4] => **kwargs).stdout
[5] => File "/usr/lib/python3.6/subprocess.py", line 423, in run
[6] => with Popen(*popenargs, **kwargs) as process:
[7] => File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
[8] => restore_signals, start_new_session)
[9] => File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
[10] => raise child_exception_type(errno_num, err_msg, err_filename)
[11] => PermissionError: [Errno 13] Permission denied: '/root/anaconda3/envs/10/bin/python3.6'