ImportError

Built-in ExceptionPython 2.0+Beginner

Raised when an import statement fails to find a module

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

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

ImportError is raised when raised when an import statement fails to find a module. Always catch specific exceptions rather than bare except clauses.

Try in Playground

Tags

exceptionerror-handlingcore