`-- MyDir
|-- FolderA
| |-- __init__.py
| |-- ScriptA.py
`-- FolderB
|-- __init__.py
|-- ScriptB.py
The above is an example of my current structure. In both FolderA and FolderB, there are .from FolderX import *
in __init__.py
, X is A or B.
I want to run ScriptB.py
which imports FolderA
first: from FolderA import *
. However, executing python ScriptB.py
under FolderB reports ModuleNotFoundError: No module named 'FolderA'
;
My current workaround to get this work is typing export PYTHONPATH=/path/to/MyDir:$PYTHONPATH
every time I start the conda environment. I would like to ask for the reason behind this and how could one avoid doing this way.
EDIT: it seems that I should have used Folder and Script to keep simplicity.