i have python 3 project that's structured this:
/project __init__.py /models __init__.py my_model.py base_model.py /tests __init__.py test.py in test.py want import my_model. first attempt from models import my_model, threw importerror: no module named 'models'. this question recommended adding __init__.py file each directory, didn't help. another post said modify path with:
import sys; import os sys.path.insert(0, os.path.abspath('..')) but throws error when my_model tries import base_model.
this seems straightforward i'm stumped. have ideas?
use absolute imports everywhere: from project.models import my_model, should work fine wherever in project, no need mess paths either.
Comments
Post a Comment