php exec python script that imports numpy

帅比萌擦擦* 提交于 2020-01-06 08:27:06

问题


I need a php script to execute a python script. Now the python code looks like this:

test.py

import sys
try:
    import numpy
    print 'Numpy was loaded'
except:
    print 'Could not Load Numpy'

All the following commands print 'Numpy was loaded':

$python test.py
$python2.7 test.py

PHP Script:

exec('python test.py',$output,$ret);
var_dump($output);

The PHP script works if the line 'import numpy' is removed.

I have tried the following things:

  1. Use absolute path in php script : exec("/usr/bin/python /home/pg/test.py"), exec("python2.7 test.py")
  2. Added absolute path of pwd and numpy using sys.path.append("path/to/numpy/dir where init.py is present")

It can be a user permission issue as well, but I have no idea.

EDIT

The exact error that python gives is :

"from numpy.linalg import lapack_lite"
  ImportError: /opt/lampp/lib/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /lib/libgfortran.so.3

来源:https://stackoverflow.com/questions/22230525/php-exec-python-script-that-imports-numpy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!