Given the following tree:
├── main.py
└── my_module
├── a.py
├── b.py
└── __init__.py
a.py:
def f():
print('Hello World.')
b.py:
from a import f
def f2():
f()
if __name__ == '__main__':
f2()
main.py:
from my_module.b import f2
if __name__ == '__main__':
f2()
When I run b.py, "Hello World." is printed successfully. However, when I run main.py, I get the following error:
Traceback (most recent call last):
File "/home/user/main.py", line 1, in <module>
from my_module.b import f2
File "/home/user/my_module/b.py", line 1, in <module>
from a import f
ModuleNotFoundError: No module named 'a'
I would expect the same output executing main.py and b.py