ModuleNotFoundError: No module named 'x'
Python can’t find the module you import — it isn’t installed in the interpreter/virtualenv that’s running, or the import path is wrong.
Meaning
Most of the time the package *is* installed — just into a different Python. pip and python can point to different interpreters, and IDEs/cron/systemd may not use your virtualenv.
Common causes
- Package not installed in the active environment
pipbelongs to a different Python thanpython(usepython -m pip)- Virtualenv not activated (IDE, cron, Docker, systemd)
- Import name differs from package name (
pip install opencv-python→import cv2,beautifulsoup4→bs4,Pillow→PIL) - Running a file inside a package directly instead of
python -m package.module - Local file shadows the module (a file named
requests.py)
⚡ Quick fix
- Install with the same interpreter:
python -m pip install <package> - Check
which python/python -c "import sys; print(sys.executable)" - Activate the virtualenv or select it in your IDE
- Rename local files that shadow library names
Detailed fix by platform
Python
- Make sure pip and python match:bash
python -c "import sys; print(sys.executable)" python -m pip install requests python -m pip show requests # Location: should be inside your venv
Docker
- Install requirements in the image (
RUN pip install -r requirements.txt) and use the same Python inCMD.
How to diagnose
- Interpreter — Which Python runs the code?
- Installed — Is the package in that interpreter?
- Name — Import name vs pip name?
- Shadowing — Local file with the same name?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026