ModuleNotFoundError usually means the code runs with a different Python interpreter or environment than the one where the package was installed.
Symptoms
- Import fails even after pip install.
- The app works locally but fails in cron, Docker or CI.
- python and pip point to different locations.
Likely causes
- Wrong virtual environment is active.
- pip installed into a different interpreter.
- PYTHONPATH or package layout is incorrect.
Fix steps
- Run python -m pip show package-name.
- Check which python and python --version in the failing environment.
- Activate the correct virtualenv or install inside the container/CI environment.
Verify the fix
- Run python -c "import package" with the same interpreter.
- Check cron, systemd or Docker command paths.
- Add dependencies to requirements or pyproject files.
FAQ
Why does pip say installed but import fails?
pip may belong to a different Python interpreter. Use python -m pip.
Can Docker use my local virtualenv?
No. Install dependencies inside the image or container environment.
Related tools and guides
Last updated: May 18, 2026