www-data user unable to import installed python modules
Question: 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.


Answer: 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
    

