Python errors › ModuleNotFoundError
ModuleNotFoundError: No module named
Updated
The Python error "No module named …" usually means the package is installed into a different Python than the one running your code. How to check, and fix it.
What you see
import requests
print(requests.get("https://example.com").status_code)Traceback (most recent call last):
File "/home/me/project/main.py", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'What it means
import requests searched every folder on sys.path of the interpreter that is running and found no module called requests. The name in quotes is the module Python looked for.
Most of the time the package is installed, just into another Python. A Mac or Linux machine often has three or four interpreters: the system one, one from Homebrew or python.org, and one inside each virtual environment. Each has its own packages.
Why it happens
pipandpythonare different interpreters.pip install requestsinstalled into the Python thatpipbelongs to, andpython3runs another one.- The virtual environment is not active, or your editor runs a different interpreter from your terminal. Check the interpreter shown in VS Code or PyCharm's status bar.
- The import name is not the package name. You install one name and import another:
beautifulsoup4isimport bs4,pillowisimport PIL,opencv-pythonisimport cv2,scikit-learnisimport sklearnandpyyamlisimport yaml. - Your own module is not on the path. Running
python app/main.pyfrom a different folder, or a sub-package imported without running it aspython -m app.main.
How to fix it
Install with the same interpreter that runs the code, by calling pip through it:
python3 -m pip install requests
If you are not sure which interpreter runs your code, ask it:
import sys
print(sys.executable)
For a project, make a virtual environment once and work inside it, so every install lands in the same place:
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
python -m pip install requests
If pip answers with "externally-managed-environment" instead, your Python refuses system-wide installs on purpose; the virtual environment above is the fix.
How each Python version words it
| Python | Prints |
|---|---|
| 3.9–3.15 | ModuleNotFoundError: No module named 'requests' |
Run on CPython 3.9.6, 3.10.22, 3.11.17, 3.12.15, 3.13.17, 3.14.9 and 3.15.1, on October 25, 2026.
The message is the same in every version here. ModuleNotFoundError was added in Python 3.6 as a subclass of ImportError, so except ImportError: still catches it.
Questions
pip says "Requirement already satisfied", but the import still fails
That pip belongs to another interpreter. Compare python3 -m pip --version, which prints the path of the Python it installs into, with sys.executable from the failing program. Install with -m pip from the one that fails.
What is the difference from ImportError?
ModuleNotFoundError means the module itself was not found. A plain ImportError such as "cannot import name 'X' from 'y'" means the module was found but the name inside it was not, or the module failed while loading.
Sources
- Built-in exceptions: ModuleNotFoundError, Python documentation
- Installing Python modules, Python documentation
- venv: creation of virtual environments, Python documentation
Read on October 25, 2026.