I've heard that Python imports can be weird and I feel really stupid for not being able to fix this myself; so please somebody kindly explain how this import situation can possibly be a problem.
Directory structure:
├── main.py
└── sub
├── sub1.py
└── sub2.py
Say sub1 defines function1:
# sub1.py
def function1():
return "function 1 result"
sub2 imports sub1 and uses function1 in function2:
# sub2.py
import sub1
def function2():
return f"function 2 result: {sub1.function1()}"
Calling function2 from main.py:
from sub.sub2 import function2
print(function2()
This throws an exception ModuleNotFoundError: No module named 'sub1'
.
Why? Shouldn't main.py see sub and sub.sub1 and sub.sub2; and shouldn't sub1 and sub2 see each other?