Django "ModuleNotFoundError: No module named settings" in CI
DJANGO_SETTINGS_MODULE names a dotted path Django cannot import. The variable is set, but the project root is not on sys.path, or the module path is wrong (for example a split settings package with no matching submodule).
What this error means
Any Django command fails while loading settings with "ModuleNotFoundError: No module named 'myproject.settings'" or "No module named 'myproject.settings.ci'".
ModuleNotFoundError: No module named 'myproject.settings.ci'
The above exception was the direct cause of the following exception:
django.core.exceptions.ImproperlyConfigured: Could not import settings 'myproject.settings.ci'Common causes
The project root is not on the import path
CI runs from a subdirectory, or the repo is checked out into a nested path, so myproject is not importable and the settings module cannot be found.
A dotted path that does not exist
You reference myproject.settings.ci but the settings package has no ci.py, or you kept a single settings.py and used a package-style path.
How to fix it
Run from the directory that holds the package
- Confirm
manage.pyand the project package sit at the checkout root. - Set
working-directoryif your Django project lives in a subfolder. - Verify the exact submodule named in DJANGO_SETTINGS_MODULE exists.
defaults:
run:
working-directory: ./backendMatch the variable to a real module
A split settings package needs an importable submodule. Point the variable at a file that exists.
# backend/myproject/settings/ci.py must exist
export DJANGO_SETTINGS_MODULE=myproject.settings.ciHow to prevent it
- Keep manage.py and the project package at the checkout root or set working-directory.
- Verify the settings submodule path exists before pushing.
- Use a src/ layout consistently so import paths are predictable.