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.
No module namedImportError: No module named 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.
Code examples
Create and use a virtual environment properly
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python app.py # same interpreter that installed the packagesSee which interpreter and paths are used
import sys
print(sys.executable) # the python actually running
print(sys.path) # where it searches for modulesIf sys.executable is not inside your venv, your IDE/cron/systemd is using another Python.
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 not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Python
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 14 Oct 2026