我只是在通过系统或exec从php调用脚本时尝试在python中导入模块时遇到了一个令人费解的问题。
I'm having a puzzling problem when trying to import a module in python only when the script is called from php via system or exec.
来自python shell :
From the python shell:
import igraph #This works.如果上一行是在一个文件中,比如test_module.py,那么: 中的b $ b python test_module.py。
if the previous line was in a file, say, test_module.py, then: python test_module.py in the bash works.
在PHP中: exec(python test_module.py,$ output,$ retval) - >失败:$ retval = 1.
Within PHP: exec("python test_module.py",$output,$retval) -> fails : $retval = 1.
但是,如果脚本是: import math ,那么这很好。
However, if the script is instead : import math, then this is fine.
有人曾经处理类似的事情吗?
Anybody ever dealt with something similar?
推荐答案要检查的一件事是 sys.path
看看每次调用的区别是什么
see what the difference is when called each way
更多推荐
从PHP调用时,python导入失败
发布评论