Python Error

ImportError

ImportError is raised when Python cannot find or load a module specified in an import statement. Its subclass ModuleNotFoundError (Python 3.6+) is raised when the module itself doesn't exist.

Common causes

  • Module or package is not installed
  • Typo in the module name
  • Circular imports between modules
  • Module not in sys.path or PYTHONPATH
  • Importing a name that doesn't exist in the module (ImportError: cannot import name)

How to fix it

  • Install the missing package: pip install package_name
  • Check for typos in the import statement
  • Use virtual environments to manage dependencies
  • Add the module directory to sys.path or PYTHONPATH
  • Resolve circular imports by restructuring code or using lazy imports

Example

ImportError example
# Error example
import nonexistent_module
# ModuleNotFoundError: No module named 'nonexistent_module'

from os import nonexistent_function
# ImportError: cannot import name 'nonexistent_function' from 'os'

# Fix: install the package
# $ pip install requests
import requests

# Fix: check available names
from os import path  # correct import

# Fix: resolve circular import with lazy import
def get_helper():
    from myapp import helper  # import inside function
    return helper

Track ImportError with Checkend

Checkend automatically captures ImportError errors in your Python application with full context:

  • Complete traceback with syntax highlighting
  • Request context (URL, params, headers)
  • Automatic grouping of similar errors
  • Instant notifications when errors occur

Stop debugging in production

Get full error context and fix issues faster with self-hosted error tracking.