Skip to main content
AllDevToolsHub
Back to error codes
ERROR ImportError

Python ImportError / ModuleNotFoundError

Python Error

Python cannot find or import the specified module.

Root Cause

The package is not installed, the virtual environment is not activated, or the module path is incorrect.

How to Fix

Install the package: pip install <package>. Activate your virtual environment. Check the module name for typos.

Quick Summary

ImportError means Python cannot find the module. Install it with pip, activate your virtual environment, and check for typos in the module name.

Key Takeaways

Key Takeaways

  • Install the package: pip install <package-name>
  • Activate virtual environment: source venv/bin/activate (Linux/macOS) or venv\Scripts\activate (Windows)
  • Check for typos, the import name may differ from the pip package name (e.g., import PIL but pip install Pillow)
  • Use pip list to see installed packages
Use Cases

When to use it

  • Package not installed
  • Virtual environment not activated
  • Wrong import name (PIL vs Pillow)
Watch out

Common Mistakes

  • Installing packages globally instead of in the virtual environment
  • Confusing the pip package name with the import name
FAQ

ImportError Python ImportError / ModuleNotFoundError, Frequently Asked

Why does pip install succeed but import still fails?

You may have multiple Python versions. Ensure you are using the same pip as your Python: python -m pip install <package> instead of just pip install.

Still having issues?

Check your network logs or use our developer tools to inspect headers, decode tokens, or validate your requests.