Home > database >  Python failure to manually import module
Python failure to manually import module

Time:03-29

I have a python script (test.py) that requests the following imports:

from MolKit import Read

The module must be installed via ADFR Suite which creates a separate directory for the module with the _init_.py file at the top. And, I have edited the ~/.bashrc to append:

export PYTHONPATH="${PYTHONPATH}:/home/ThoughtfulHistorian/ADFRsuite-1.0/ADFRsuite_x86_64Linux_1.0/CCSBpckgs/MolKit"

Before running source ~/.bashrc. Still, the script returns an import failure:

File "test.py", line 2, in <module>
    from MolKit import Read
ModuleNotFoundError: No module named 'MolKit'

I am running Python 3.8.10 on Ubuntu 20.04.4 LTS.

CodePudding user response:

It is the directory containing the package directory which needs to be on PYTHONPATH, not the package directory itself.

Instead of

export PYTHONPATH="${PYTHONPATH}:/home/ThoughtfulHistorian/ADFRsuite-1.0/ADFRsuite_x86_64Linux_1.0/CCSBpckgs/MolKit"

use

export PYTHONPATH="${PYTHONPATH}:/home/ThoughtfulHistorian/ADFRsuite-1.0/ADFRsuite_x86_64Linux_1.0/CCSBpckgs"
  • Related