I have a project which I want to structure like this:
myproject
├── api
│ ├── __init__.py
│ └── api.py
├── backend
│ ├── __init__.py
│ └── backend.py
├── models
│ ├── __init__.py
│ └── some_model.py
└── __init__.py
Now, I want to import the module some_model.py
in both api.py
and backend.py
. How do I properly do this?
I tried:
from models import some_model
but that fails with ModuleNotFoundError: No module named 'models'
.
I also tried:
from ..models import some_model
which gave me ValueError: attempted relative import beyond top-level package
.
What am I doing wrong here? How can I import a file from a different directory, which is not a subdirectory?
myproject
package, which OP has tried. What would cause that not to work? – Gimel