Lingua-e
Python

What is a ImportError?

← Errors

An ImportError is raised in Python when an import statement fails. This can mean the module itself does not exist, or the specific name you are trying to import from the module is not found inside it.

Why it happens

  • The module is not installed in the current Python environment.
  • Typo in the module name or the imported name.
  • Importing a name that does not exist or was renamed in a newer version.
  • Circular imports where module A imports B and B imports A.

Examples

Python

Code that triggers the error

from myutils import helper_function

result = helper_function("data")

Error output

Traceback (most recent call last):
  File "app.py", line 1, in <module>
    from myutils import helper_function
ImportError: cannot import name 'helper_function' from 'myutils'

How to fix it

Install the missing package with pip install <package>. Check the module's documentation or source to verify the exact names it exports. Use a virtual environment to avoid version conflicts. For circular imports, restructure to extract shared code into a third module.

Fixed code

# Check what is actually exported from myutils
# Option 1: import the module and check available names
import myutils
print(dir(myutils))

# Option 2: use the correct name
from myutils import process_data  # use the actual function name

Related errors

Ready to practice your English at work?

Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.

Try Lingua-e for free