I have a project structure like that:
main.py src foo.py bar.py
And I am trying to import
# main.py import src.foo # I also tried # from src import foo # or # from src.foo import *
# foo.py import bar # also tried # from bar import *
But it has ModuleNotFoundError.
ModuleNotFoundError: No module named 'bar'
It worked when I did in
foo.py something like this:
But I don’t want to do that every time I import something. Why can’t the imported module use its own parent directory and how can I fix it?
Source: Python Questions