I am new in python programming and I encounter some problem when I use import statement.
The following is my directory.
package/
__init__.py
main.py
subpackage_a/
__init__.py
a.py
subpackage_b/
__init__.py
b.py
In package/main.py
I use import package.subpackage_a.a
to import a.py
.
In package/subpackage_a/a.py I try to add package/subpackage_a/subpackage_b
to PYTHONPATH by modifying sys.path
in a.py
and use import b
to import b.py
.
However, when I run package/main.py
, the ModuleNotFoundError appear.
Although changing PYTHONPATH arbitrarily is not a good habit, I still want to know why I can't successfully import package/subpackage_a/subpackage_b/b.py
by modifying sys.path
in package/subpackage_a/a.py
when I run package/main.py
.
Thanks a lot.