ModuleNotFoundError in Python — What It Means and How to Fix It
What Python's ModuleNotFoundError exception means and how to resolve it.
Published October 27, 2026
ModuleNotFoundError is raised when Python cannot find a module you import. Usually the package is not installed in the active environment.
What it means and why it happens
Typical causes: package not installed, wrong virtual environment, different Python version or a typo in the name.
Read the full message: it names the file and line where the problem was detected, which is the best place to start.
What you see
run the code
ModuleNotFoundError: No module named 'requests'
Practical examples
Code that triggers it
import requestsThe fix
# install into the active environment
# python -m pip install requests
import requestsCheck the environment
which python
python -m pip list | grep requests
python -m pip install requestsCommon mistakes
- Installing with a different pip than python.
- Not activating the virtualenv.
- Naming your file requests.py.
Key takeaways
- ModuleNotFoundError: ModuleNotFoundError is raised when Python cannot find a module you import.
- Read the message and the line number first.
- Fix the cause, don't just silence the error.
FAQ
Why does pip install not help?
pip and python may belong to different environments; use python -m pip.
How do I find which line caused ModuleNotFoundError?
The error message and stack trace show the file and line; start there and work backwards.