You must run the python script from php. I use the following code

$python = exec('python bla.py'); echo "Python is printing: " . $python; 

If the python file contains relatively simple code, like print (123) then everything works fine, but if the code is more complex, then if you put print (123) after the import block, the $ python variable is empty? How to understand this?


Unfortunately, the situation does not change. Try writing to bla.py

 import requests print(123) 

This is python 2.7. Output in exec will not be


Problem solved. The code was incorrect, so there was an error. Respectively helped 2> & 1

    1 answer 1

    exec returns the last line from the command output, not the entire output.

    http://php.net/manual/ru/function.exec.php

    better do this:

     $python = []; exec('python bla.py', $python); echo "Python is printing: " . implode(PHP_EOL, $python); 
    • does not work unfortunately ( - MasterParser