简体   繁体   English

www-data用户无法导入已安装的python模块

[英]www-data user unable to import installed python modules

I am trying create a web-server which ultimately calls a python script ("MyScript.py") from PHP code with the following command 我正在尝试创建一个Web服务器,该服务器最终使用以下命令从PHP代码调用python脚本(“ MyScript.py”)

echo exec("MyScript.py ....some arguments")

MyScript.py actually contains a code which uses RDkit and other modules like numpy. MyScript.py实际上包含使用RDkit和其他模块(如numpy)的代码。
When I run this MyScript.py from user (MKT)....it works like a charm. 当我从用户(MKT)运行此MyScript.py时。

But the problem arises when it get executed from PHP script from server. 但是问题是从服务器的PHP脚本执行时出现的。 The error message in /var/www/log/apache2/error.log is as follows: /var/www/log/apache2/error.log中的错误消息如下:

ImportError: No module named rdkit
Traceback (most recent call last):
File "./preditar/preditar.py", line 7, in <module>
from rdkit import Chem

My rdkit is installed in /opt/RDKit_2013_06_1/rdkit/ and this the following the result if run them from MKT user 我的rdkit安装在/ opt / RDKit_2013_06_1 / rdkit /中,如果从MKT用户运行它们,则会显示以下结果

MKT@mypc$ python -v

and then in python environment: 然后在python环境中:

import rdkit

Here is the output: 这是输出:

import rdkit # precompiled from /opt/RDKit_2013_06_1/rdkit/\__init__.pyc

I think user www-data which executes this do not have access to this module...then how to import this in MyScript.py??? 我认为执行此操作的用户www-data无法访问此模块...然后如何在MyScript.py中导入它?

Note: When I modify MyScript.py to a simple script which just create a file and write data to it...it works properly without any issue that means I don't have any problem related to permission. 注意:当我将MyScript.py修改为一个简单的脚本,该脚本仅创建一个文件并向其中写入数据时,它可以正常工作而不会出现任何问题,这意味着我没有与权限相关的任何问题。

Looks like problem with Python import search path. 看起来像Python导入搜索路径的问题。 Try to change the import like this: 尝试像这样更改导入:

import sys
sys.path.insert(0, "/opt/RDKit_2013_06_1")
import rdkit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM