www-data user unable to import installed python modules

前提是你 提交于 2021-02-08 10:51:28

问题


I am trying create a web-server which ultimately calls a python script ("MyScript.py") from PHP code with the following command

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

MyScript.py actually contains a code which uses RDkit and other modules like numpy.
When I run this MyScript.py from user (MKT)....it works like a charm.

But the problem arises when it get executed from PHP script from server. The error message in /var/www/log/apache2/error.log is as follows:

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

MKT@mypc$ python -v

and then in python environment:

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???

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.


回答1:


Looks like problem with Python import search path. Try to change the import like this:

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


来源:https://stackoverflow.com/questions/25590460/www-data-user-unable-to-import-installed-python-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!