'Python failure to manually import module

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.



Solution 1:[1]

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"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 wim