So I'm trying to import a module from package that import its subpackage. Here is sample code:
main_directory
- main.py
subdirectory
- __init__.py
- test.py
subsubdirectory
- __init__.py
- test2.py
main.py:
from subdirectory import test
test.foo1()
test.py:
from subsubdirectory import test2
def foo1():
print("foo1")
test2.foo2()
test2.py:
def foo2():
print("foo2")
in this case, if I change
from subsubdirectory import test2
to
from .subsubdirectory import test2
it works since I guess it's direct path? But when I move to my subdirectory and run python3 test.py it will throw error:
ModuleNotFoundError: No module named '__main__.subsubdirectory'; '__main__' is not a package
Can you explain what happened?