从PHP调用时,python导入失败 [英] python import fails when called from PHP

查看:177
本文介绍了从PHP调用时,python导入失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在通过系统或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导入失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆