ModuleNotFoundError

Built-in ExceptionPython 2.0+Beginner

Subclass of ImportError; raised when a module cannot be located

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
# Triggering and catching ModuleNotFoundError
try:
    import nonexistent_module_xyz
except ModuleNotFoundError as e:
    print(f"Caught ModuleNotFoundError: {e}")
    print(f"Type: {type(e).__name__}")

ModuleNotFoundError is raised when subclass of importerror; raised when a module cannot be located. Always catch specific exceptions rather than bare except clauses.

Try in Playground

Tags

exceptionerror-handlingcore