I have a python script main.py
which imports various modules from other scripts in the same directory.
With the lines
import sys
print(sys.path)
I can see that when I run main.py
, the directory it is in (binBuild
below) is added to the PYTHONPATH
along with the python version I am using (python3.5
from miniconda)
['/ms/data5/USERNAME/Programmes/MYCODE/binBuild', '/ms/data5/USERNAME/Programmes/MYCODE/miniconda3/lib/python35.zip', '/ms/data5/USERNAME/Programmes/MYCODE/miniconda3/lib/python3.5', '/ms/data5/USERNAME/Programmes/MYCODE/miniconda3/lib/python3.5/plat-linux', '/ms/data5/USERNAME/Programmes/MYCODE/miniconda3/lib/python3.5/lib-dynload', '/ms/data5/USERNAME/Programmes/MYCODE/miniconda3/lib/python3.5/site-packages', '/ms/data5/USERNAME/Programmes/MYCODE/miniconda3/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg']
main.py
contains two options - it can run directly, or, with a flag specified it can call a gui. At this stage main.py runs with no errors.The gui contains various options that can be set and then when processing is started calls back to main.py
to start the main run of the code. At this point the code fails with the following error:
Traceback (most recent call last):
File "/ms/data5/USERNAME/Programmes/MYCODE/binBuild/GUI/../main.py", line 12, in <module>
from GlobalParams import GlobalParams
ModuleNotFoundError: No module named 'GlobalParams'
If I print the PYTHONPATH
at this stage I can see that the PYTHONPATH
now contains two copies of the path to the directory containing main.py
.
['/ms/data5/USERNAME/Programmes/MYCODE/binBuild', '/ms/data5/USERNAME/Programmes/MYCODE/binBuild', '/ms/data5/USERNAME/Programmes/MYCODE/miniconda3/lib/python35.zip', '/ms/data5/USERNAME/Programmes/MYCODE/miniconda3/lib/python3.5', '/ms/data5/USERNAME/Programmes/MYCODE/miniconda3/lib/python3.5/plat-linux', '/ms/data5/USERNAME/Programmes/MYCODE/miniconda3/lib/python3.5/lib-dynload', '/ms/data5/USERNAME/Programmes/MYCODE/miniconda3/lib/python3.5/site-packages', '/ms/data5/USERNAME/Programmes/MYCODE/miniconda3/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg', '/ms/data5/USERNAME/anaconda3/lib/python37.zip', '/ms/data5/USERNAME/anaconda3/lib/python3.7', '/ms/data5/USERNAME/anaconda3/lib/python3.7/lib-dynload', '/ms/data5/USERNAME/anaconda3/lib/python3.7/site-packages']
I also notice at this stage it picks up another copy of python (3.7) which is installed elsewhere on the system.
However, python is no longer able to import any of the modules from the binBuild
directory (where main.py
is present). Why can python no longer find modules even though they are in a directory on its path. Is this expected behaviour?