I have a Python 3 project that's structured like this:
/project
__init__.py
/models
__init__.py
my_model.py
base_model.py
/tests
__init__.py
test.py
In test.py
I want to import my_model
. My first attempt was from models import my_model
, which threw an ImportError: No module named 'models'
. This question recommended adding an __init__.py
file to each directory, which didn't help. Another post said to modify the path with:
import sys; import os
sys.path.insert(0, os.path.abspath('..'))
but this throws an error when my_model
tries to import from base_model
.
This seems really straightforward but I'm stumped. Does anyone have any ideas?