Skip to content

/errors/python/modulenotfounderror-no-module-named

ModuleNotFoundError: No module named '…'

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · Python 3.13.15updated 2026-10-20
tool
Python
exit code
1
versions
Python 3.6+
os
any

Python raises ModuleNotFoundError: No module named 'x' when the interpreter running your code cannot find module x on its import path. Almost always the package is either not installed, or installed for a different interpreter or virtual environment.

Reproduce the error

bash
python -c "import requests"

Output · exit 1

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'

The process exits with status 1 and the traceback names the missing module.

Check which interpreter runs your code

Install packages with the same interpreter that runs the code. python -m pip guarantees that, while a bare pip may belong to another Python on PATH.

bash
python -c "import sys; print(sys.executable)"
python -m pip --version

Both lines must point inside the same environment (the active virtual environment, or the system installation).

Check whether a module is importable without importing it

importlib.util.find_spec returns None when a module cannot be found, which is useful in scripts and health checks.

bash
python -c "import importlib.util as u; print(u.find_spec('json') is not None, u.find_spec('requests') is not None)"

Output

True False

Fix

  1. Install into the interpreter you run: python -m pip install requests.
  2. In a virtual environment, activate it first (source .venv/bin/activate on Linux and macOS, .venv\Scripts\activate on Windows), or run .venv/bin/python directly.
  3. Use the import name, not the distribution name. Common mismatches:
pip installimport
PyYAMLyaml
PillowPIL
scikit-learnsklearn
beautifulsoup4bs4
opencv-pythoncv2
python-dateutildateutil

FAQ

What is the difference between ImportError and ModuleNotFoundError?

ModuleNotFoundError is a subclass of ImportError raised when the module itself cannot be located. ImportError alone usually means the module was found but a name inside it could not be imported.

Why does pip say the package is installed but Python cannot import it?

pip and python point to different interpreters. Run python -m pip install so the package lands in the environment of the interpreter you use.

Sources