Exception Attributes
ImportError.path — exception attribute
Inspect the file path associated with an import failure when the importer supplies it. A missing module may not have a source path. This example uses an explicit constructor to simulate a loader diagnostic; it does not access a file.
Formal Syntax & Structure
python syntaxpython
error.pathReturn Value
str | None
Associated file path when supplied.
Working Example
Example Snippetpython
error = ImportError("invalid module", name="demo", path="demo.py")print(error.path)print(ImportError().path)