fuckingpython.lol

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

main.py
import requests

print(requests.get("https://example.com").status_code)
Python 3.15 prints
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

  • pip and python are different interpreters. pip install requests installed into the Python that pip belongs to, and python3 runs 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: beautifulsoup4 is import bs4, pillow is import PIL, opencv-python is import cv2, scikit-learn is import sklearn and pyyaml is import yaml.
  • Your own module is not on the path. Running python app/main.py from a different folder, or a sub-package imported without running it as python -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

PythonPrints
3.9–3.15ModuleNotFoundError: 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

Read on October 25, 2026.