I have the following structure
abc/ __init__.py settings.py tests/ __init__.py test.py in test.py, I am getting an ImportError for
#test.py import abc.settings You have two ways.
Firstly, by setting the path variable
import os import sys sys.path.insert(0, <Complete path of abc>) Or by using relative imports.
from ..abc import settings and ran it with python -m but I'm still getting an errorThe variable
sys.pathis a list of strings that determines the interpreter’s search path for modules. It is initialized to a default path taken from the environment variablePYTHONPATH, or from a built-in default ifPYTHONPATHis not set. You can modify it using standard list operations:
you need to add your root directory to sys.path :
import sys sys.path.append('path_of_root') Aldo '..'+sys.path[0] can give you the path of abc directory !
abcis in), to yoursys.path