I have the following directory structure and files:
├── a
│ ├── b
│ │ ├── b.py
│ └── c
│ ├── c.py
└── main.py
# main.py
from a.b import b
print('i am main')
# a/b/b.py
from a.c import c
print('i am b')
# a/c/c.py
print('i am c')
The following works just fine and is expected.
» python3 main.py
i am c
i am b
i am main
However, if I go inside the directory a/b
and run
python3 b.py
I get:
» python3 b.py
Traceback (most recent call last):
File "b.py", line 1, in <module>
from a.c import c
ModuleNotFoundError: No module named 'a'
And if I try to run it from the root of the project I get
» python3 a/b/b.py
Traceback (most recent call last):
File "a/b/b.py", line 1, in <module>
from a.c import c
ModuleNotFoundError: No module named 'a'
It makes sense that it can't find the module which is one level above the directory but how would one run a/b/b.py
script in this scenario?