Difference between calling a python script by terminal and by PHP? Where is the Error?

前端 未结 2 1613
暖寄归人
暖寄归人 2021-01-06 11:39

I have a PHP script, that calls a python script by

$call_python = \"python ../python/lp_3.py \".$author;
$python_output = Null;
$mystring = exec($call_python         


        
相关标签:
2条回答
  • 2021-01-06 11:42

    In your PHP code, you're just calling "python", and letting PHP decide which version of Python to use. Use an explicit path to a specific Python binary, (e.g. /usr/bin/python2.6).

    You need to know the exact path to the version of Python that has MySQLdb installed.

    0 讨论(0)
  • 2021-01-06 11:44
    $call_python = "/opt/local/bin/python2.6 ../python/lp_3.py ".$author;
    $python_output = Null;
    $mystring = exec($call_python, $output_python);
    

    did the job. Like @AJ pointed out, I had to tell python which version to chose. I chose a version where MySQLdb was available and all was fine.

    0 讨论(0)
提交回复
热议问题