What does ImportError cannot import name mean in Python?

Updated October 2026 · How we answer

Short answerThis error means Python found the module but could not find the name you asked to import from it. Common causes are a typo, a different library version, or a circular import between your own files.

Typical causes

The line from module import name fails when the module does not define that name. This can happen when a function was renamed or removed in a newer library version, or when the name lives in a submodule and you imported the wrong path.

A circular import is another common cause. If file A imports from file B while B is still loading and imports from A, the name may not be defined yet. The error message names the missing item, which helps you check the source.

  • Check the spelling and capitalization of the name
  • Compare the library version to the docs you are reading
  • Look for two files that import each other

How to fix it

Confirm the name exists by opening the module file or checking its documentation. Installing the version the tutorial uses can also help when the API changed. Virtual environments sometimes hold an older package, so check which version is active.

For circular imports, move shared code into a third module, or import the module itself and access the name inside a function instead of at the top of the file.

When a library is typed with any or has missing type definitions, the compiler may behave differently than you expect. Installing the matching type package often resolves similar errors.

Common mistakes

  • Installing a different package with the same name as the one you meant.
  • Ignoring a stale virtual environment that still has an older library version.
From our shopsCASEONYX: Dark-luxe tough phone cases.