Python "ModuleNotFoundError: No module named X" in CI
Python could not import a module. Either it was never installed for the interpreter running your code, or your own package layout puts it somewhere not on sys.path.
What this error means
The program or test run aborts with ModuleNotFoundError: No module named X. It can be a third-party package (not installed) or one of your own modules (not importable from where it runs).
Traceback (most recent call last):
File "app/main.py", line 2, in <module>
from app.utils import helper
ModuleNotFoundError: No module named 'app'Common causes
Package not installed for this interpreter
A third-party import fails because it was installed into a different interpreter or venv than the one running the code.
Your own package is not on sys.path
For first-party imports like from app..., the project root is not on sys.path - usually because the package was not installed (pip install -e .) and CI runs from a different directory.
Missing __init__.py or wrong layout
A directory that should be an importable package may be missing an __init__.py, or the src-layout means the package only resolves after an editable install.
How to fix it
Install the dependency into the active interpreter
python -m pip install <package>
python -c "import <package>; print(<package>.__file__)"Install your project so first-party imports resolve
An editable install puts your package on sys.path regardless of working directory.
pip install -e .
# or for src-layout projects, ensure pyproject defines the packageConfirm the interpreter and path
- Run
which python/python -m siteto see the interpreter and its site-packages. - If a venv is involved, make sure it is the one running the failing step.
- For first-party modules, prefer an editable install over
sys.pathhacks.
How to prevent it
- Install your project with
pip install -e .in CI so imports are stable. - Use one consistent venv across all steps.
- Adopt a clear src-layout and declare packages in
pyproject.toml.