Built-in Exceptions

ModuleNotFoundError — exception class

Specializes ImportError for a module that cannot be located (also when a module entry in sys.modules is None). A missing dependency inside another module can raise it too; inspect name before assuming the top-level package is absent. Catch ModuleNotFoundError when this category is the recovery boundary; do not rely on the exact human-readable message.

Formal Syntax & Structure

python syntaxpython
ModuleNotFoundError

Return Value

type

The class object ModuleNotFoundError; this reference documents the class identity, not a universal constructor signature.

Working Example

Example Snippetpython
try:    __import__("bytemind_missing_module_27_8d71")except ModuleNotFoundError as error:    print(type(error).__name__)
Python Reference