Search code examples
pythonpython-importpython-module

Python ImportError loading module within subfolder


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

Solution

  • 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.