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 an import statement can't find the specified module.
Key points
- Catch it specifically with "except ModuleNotFoundError:" when you want to handle this exact case rather than a bare except
Example
import nonexistent_module # ModuleNotFoundError