I have a Python project structured as follows:
projectX/
├── __init__.py
├── main.py
├── functions/
│ ├── __init__.py
│ └── hello.py
└── test/
├── __init__.py
└── test.py
from main.py I can import the hello.py module without any issues: from functions.hello import greet
from test.py, I’m trying to import the module hello.py with the statement: from functions.hello import greet
but I get the following error: ModuleNotFoundError: No module named ‘functions’
My init.py modules are just empty .py scripts
I’ve tried using relative paths from ..functions.hello import greet
which gives the following error: attempted relative import with no known parent package
I’ve also attempted to modify the sys.path in test.py to include the parent directory of my project using the following code: sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
I’ve visited the following SO questions but I’m still confused as to how you make this import work: Relative imports for the billionth time