ModuleNotFoundError: No module named '[module]'
This error matches known, documented patterns with reliable solutions.
Quick Fix (Most Common Solution)
- Install the module: pip install [module-name] (or pip3 for Python 3 specifically)
- If using a virtual environment, confirm it is activated before installing
Seeing "ModuleNotFoundError: No module named"? This error can be frustrating, but it's usually fixable. It typically affects your development workflow or system. Below you'll find clear, step-by-step solutions to resolve this issue.
What This Error Means
Python cannot find the module you are trying to import. Either the package is not installed in the active Python environment, or you are running the script with a Python interpreter different from the one where the package was installed.
Frequently documented in developer and vendor support forums.
Not affiliated with browser, OS, or device manufacturers.
New here? Learn why exact error messages matter →
Common Causes
- Module is not installed in the currently active Python environment
- Module is installed globally but a virtual environment is active (or vice versa)
- Module installed for Python 2 but Python 3 is running (or vice versa)
- Typo in the import statement — module name and import name do not always match
How to Fix
- Install the module: pip install [module-name] (or pip3 for Python 3 specifically)
- If using a virtual environment, confirm it is activated before installing
- Verify the module installed in the correct location: pip show [module-name]
- In VS Code or Jupyter, confirm the Python interpreter is set to the environment with the module
Last reviewed: June 2026 How we review solutions
Didn't fix it? Get a personalised solution
Environment-Specific Commands
Install the module (most common fix)
pip install [module-name]pip3 install [module-name]python -m pip install [module-name]
Virtual environment — activate and install
source venv/bin/activatepip install [module-name]python -c "import [module-name]; print('OK')"
Windows — virtual environment
venv\Scripts\activatepip install [module-name]python -c "import [module-name]"
Quick Diagnostic Path
- If pip show [module] says not installed → Run: pip install [module-name] — then retry the script
- If pip show says installed but import fails → Run: which python (or python --version) and match it to the pip that installed. Use python -m pip install to guarantee the match.
- If Error in Jupyter notebook → Run inside a Jupyter cell: !pip install [module] then restart the kernel
If This Still Fails, Check
- Package name vs import name: 'scikit-learn' is installed as sklearn, 'Pillow' as PIL, 'beautifulsoup4' as bs4. Always check the package docs for the correct import name.
- Python 2 vs Python 3: if both are installed, 'python' may invoke Python 2. Use 'python3' and 'pip3' explicitly.
- System-level dependencies: some packages (lxml, psycopg2, cryptography) require OS libraries. Install: sudo apt install python3-lxml or use the binary wheel: pip install psycopg2-binary
Diagnose and fix ModuleNotFoundError
# Step 1: install the module
pip install [module-name]
# Step 2: verify where it installed
pip show [module-name]
# Check the "Location" field — is it in your venv or system Python?
# Step 3: test the import
python -c "import [module-name]; print('OK')"
# Step 4: if using a virtual environment
source venv/bin/activate # Linux/Mac
# venv\Scripts\activate # Windows
pip install [module-name]
python -c "import [module-name]; print('OK')"Common Misdiagnoses
Modulenotfounderror Is Often a Dependency Version Mismatch, Not a Code Bug
Modulenotfounderror appears after updating a package or upgrading Python, the error is often misdiagnosed as a bug in your code when the root cause is an incompatible dependency combination.
The diagnostic workflow: check when the error started appearing — was it after a pip install, a pip upgrade, or a Python version change? Run pip show <package> to see the currently installed version and compare with what your code was written against. Run pip check to list all dependency conflicts in the current environment. For complex dependency trees, pipdeptree shows the full graph and highlights conflicts. If the error appeared after pip install --upgrade, downgrade with pip install <package>==<previous-version> and verify the error goes away — this confirms the dependency is the cause. Use pip freeze > requirements.txt to capture a known-good state and pip install -r requirements.txt to restore it. Pin versions in production requirements to prevent upgrades from introducing Modulenotfounderror silently.Optional follow-up
Some users ask whether saving fixes for recurring errors would be useful when the same issue appears again.
Was this explanation helpful?
Frequently Asked Questions
I installed the package but the error persists
You may have installed it for a different Python. Run: python -m pip install [module] — using python -m ensures the package installs for the exact interpreter you are running.
How do I activate a virtual environment?
Linux/Mac: source venv/bin/activate. Windows: venv\Scripts\activate. After activation, your shell prompt shows the venv name in parentheses.
pip install worked but import still fails in Jupyter
Jupyter may use a different Python kernel. Run inside a Jupyter cell: !pip install [module] — then restart the kernel (Kernel > Restart).
Also Known As
- Python exception
- Python traceback
- Python runtime error
- Python crash
Common Search Variations
- "python error fix"
- "python script not working"
- "python traceback what does it mean"
- "how to fix python exception"
- "python crash on startup"
- "python import error solution"
Related Errors
Still Stuck?
Paste a different error message or upload a screenshot to get help instantly.