ModuleNotFoundError: No module named 'x'
Error message
No module named 'x'
Quick summary
Python can't find the module you're trying to import — it's not installed, not in the Python path, or the name is wrong.
Why this happens
The module is not installed in the current environment
Typo in the module name
Wrong virtual environment is activated
The module is not in
PYTHONPATHor the current directory
Minimal example
import numpy # ModuleNotFoundError if not installed# Run: pip install numpy
import numpynumpy isn't installed in the current environment — install it with pip install numpy before importing.
How to diagnose
Run
pip listto see if the module is installedVerify the module name spelling against the import
Check which Python/venv is active with
which pythonorpython -V
How to fix
Install the module with
pip install <module>Fix the module name typo in the import statement
Activate the correct virtual environment before running
How to prevent
Use
requirements.txtorpyproject.tomlto track dependenciesUse virtual environments to manage installed packages per project
Related Resources
Related Glossary
Related Lessons
- Python Overview
Learn Python fundamentals including imports
Related Practice
- Python Variable Naming Quiz
Test your knowledge of Python naming and imports.