ModuleNotFoundError —
Python looked, and couldn't find it.
Python searches a specific list of locations for a module, in a fixed order, and if the name you imported isn't found in any of them, this is the result. It's almost always a setup issue — not installed, wrong name, or wrong environment — not a bug in your logic. Watch Python's module search path get checked on LearnBug and see exactly where it comes up empty.
What is ModuleNotFoundError?
Raised when Python's import statement can't locate the named module anywhere in sys.path — a specific, ordered list of directories Python searches, including your current script's directory, installed site-packages, and any directories listed in the PYTHONPATH environment variable.
Why visualization helps
Unlike most errors on this hub, this one isn't really about code logic — it's about environment. LearnBug can't fix a missing package install for you, but understanding exactly what Python checked and in what order turns a confusing "why can't it find this" moment into a clear, mechanical troubleshooting checklist.
Three reasons Python can't find your import
Package not installed
Third-party packages (like requests, numpy, pandas) don't come with Python by default — they must be installed with pip first.
Installed in a different Python environment
A package installed in one virtual environment (or a different Python version) isn't visible to a script running under a different environment.
Wrong module name
Some packages have a different install name than import name — pip install beautifulsoup4 but import bs4, for example.
import requests without it installed
import requests triggers Python's module search
Python checks a specific ordered list of locations: the script's own directory, then built-in standard library modules, then installed third-party packages in site-packages.
No requests.py in the script's directory. No "requests" in the standard library either
requests is a third-party package — it was never part of Python's built-in standard library, so this check always fails for it unless it's specifically installed.
site-packages is also checked — requests was never pip installed, so it's not there either
This is the location where pip install would have placed it. Since that command was never run in this environment, the package genuinely doesn't exist anywhere Python looks.
Result: ModuleNotFoundError: No module named 'requests' ✗
The broken code, and the traceback it produces
import requests # not installed in this environment
response = requests.get("https://example.com")
print(response.status_code)Traceback (most recent call last):
File "fetch.py", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'Install the package into the environment you're running
# Install the package (in the same environment your script runs in)
pip install requests
# If you use multiple Python versions, be explicit:
python3 -m pip install requests
# If using a virtual environment, activate it FIRST, then install:
source venv/bin/activate
pip install requestsQuick Reference
Frequently asked questions
I already ran pip install — why is it still not found?
Almost always an environment mismatch — you installed the package into a different Python interpreter or virtual environment than the one actually running your script. Check with which python (or where python on Windows) that both the install command and your script are using the same interpreter.
Why is my import name different from what I typed in pip install?
A package's PyPI distribution name (what you type after pip install) doesn't have to match its Python import name — beautifulsoup4 is imported as bs4, and Pillow is imported as PIL, for example. Check the package's documentation for the correct import name if installing didn't seem to fix it.
What's the difference between ModuleNotFoundError and ImportError?
ModuleNotFoundError is a more specific subclass of ImportError, introduced to distinguish "the module doesn't exist at all" from other import failures — like a module that exists but fails partway through its own initialization code, or a specific name you tried to import from inside a module that isn't actually defined there.
Why does it work on my machine but not on a teammate's / a server?
Each machine or environment has its own independently installed set of packages — installing something locally doesn't install it anywhere else. Use a requirements.txt file (generated with pip freeze) and have every environment run pip install -r requirements.txt to keep dependencies consistent across machines.
See exactly what Python could and couldn't find
Paste your import statements into LearnBug to check for other bugs once your environment is set up.