doupiao1893 2018-10-08 16:58
浏览 259
已采纳

Python脚本在通过PHP执行时找不到模块,但在通过CLI运行时可以找到它

Having an issue when I try to run a python script via my PHP frontend I've tried both of the following:

$command = "(python3 /my/script.py --params) 2>&1";
$output = shell_exec($command);

and

ob_start();
passthru($command);
$output = ob_get_clean();

Both return:

Traceback (most recent call last): File "/my/script.py", line 14, in from woocommerce import API ModuleNotFoundError: No module named 'woocommerce'

When run through the CLI, the script works just fine, but it throws the above when run through PHP. This is the line in question giving me issues. At a loss as to why it can find the module in one instance and not the other.

from woocommerce import API
from wordpress_json import WordpressJsonWrapper
  • 写回答

1条回答 默认 最新

  • doushi1960 2018-10-08 17:08
    关注

    looks like your woocommerce module is not correctly installed in the system. It can be found when running the script in CLI, but when the system user that controls your PHP instance starts the script, the woocommerce module is not there. That indicates this module is installed for your normal CLI user only, and not globally in the system.

    The direct solution is to install the woocommerce module globally, so that other users (including the system user that runs PHP) can find it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证