ModuleNotFoundError Python Origin: Application & API Last updated 14 Oct 2026

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.

Exact message you may see No module namedImportError: No module named
Seen on: Python Docker

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
  • pip belongs to a different Python than python (use python -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

  1. Install with the same interpreter: python -m pip install <package>
  2. Check which python / python -c "import sys; print(sys.executable)"
  3. Activate the virtualenv or select it in your IDE
  4. Rename local files that shadow library names

Detailed fix by platform

Python

  1. 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

  1. Install requirements in the image (RUN pip install -r requirements.txt) and use the same Python in CMD.

Code examples

Create and use a virtual environment properly

bash
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 packages

See which interpreter and paths are used

python
import sys
print(sys.executable)   # the python actually running
print(sys.path)         # where it searches for modules

If sys.executable is not inside your venv, your IDE/cron/systemd is using another Python.

How to diagnose

  1. Interpreter — Which Python runs the code?
  2. Installed — Is the package in that interpreter?
  3. Name — Import name vs pip name?
  4. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

0x8007007E — 0x8007007E: The specified module could not be found (Windows)0x8007007EClass not found — PHP Fatal error: Uncaught Error: Class "X" not found (PHP)Class not foundClassNotFoundException — java.lang.ClassNotFoundException / NoClassDefFoundError (Java)ClassNotFoundExceptionDependency requires compileSdk — Dependency 'androidx.x:1.y' requires libraries and applications that depend on it to compile against version 34 or later of the Android APIs (Android)Dependency requires c…externally-managed-environment — error: externally-managed-environment (Python)externally-managed-en…gyp ERR! — gyp ERR! build error / node-gyp rebuild failed (npm)gyp ERR!held broken packages — Unmet dependencies / E: Unable to correct problems, you have held broken packages (Linux)held broken packagesImportError — ImportError: cannot import name 'x' from 'y' (Python)ImportErrorModuleNot…

Explore the map of this error Full error map →

🧠 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.