I have the following project structure:
├── my_app
├── __init__.py
├── my_pkg
│ ├── __init__.py
│ ├── utils.py
│ ├── app.py
├── other_pkg...
│ ├── __init__.py
│ ├── ...
├── ...
I want in the my_app/my_pkg/app.py
to import utils
. I want to call that Python file from anywhere. For example, I want to be in my_app
and run python my_pkg/app.py
.
Adding the following line in app.py
throws the exception ModuleNotFoundError: No module named my_app
:
from my_app.my_pkg import utils
I know I can add the path to sys.path but I don't want to do that. I don't understand why Python can't consider the above project structure as a package and just import the files. I find it really ugly to add paths to sys to get Python to find the files!
Any suggestions?