I’ve made a minimal example project to attempt to resolve my module imports issue. The structure is as follows:
MyProject/ ├── main.py └── utils/ ├── __init__.py ├── foo.py └── bar.py
main.py only contains this code:
from utils import foo
__init__.py does not contain any code
foo.py only contains this code:
from bar import Bar
bar.py only contains this code:
class Bar: pass
If I run
python utils/bar.py, it runs with no exceptions.
Similarly, if I run
python utils/foo.py, it runs with no exceptions.
However, if I run
python main.py, it results in the following exception:
ModuleNotFoundError: No module named 'bar'
Is there any way to resolve this issue? Or is it even an issue, perhaps I’m doing something I’m not supposed to?
Source: Python Questions