从PHP调用时,python导入失败

编程入门 行业动态 更新时间:2024-10-21 19:06:59
本文介绍了从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导入失败

本文发布于:2023-10-24 14:02:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524123.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PHP   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!