Importerror: cannot import name ‘iterable’ from ‘collections’

Are you encountering reads “ImportError: cannot import name ‘iterable’ from collections“?

This error means that the code is trying to import the “iterable” module from the “collections” package, but it cannot find it.

Obviously, there is a version mismatch between the Python version and the package being imported.

So in this article, we determined how to fix this error…

What is Importerror: cannot import name ‘iterable’ from ‘collections’?

The error “ImportError: cannot import name ‘iterable’ from ‘collections‘” means that there was an attempt to import the ‘iterable’ module from the ‘collections’ module in Python, but the interpreter was unable to find it.

Moreover, the error can occur if the version of Python being used is older than the one that introduced the ‘iterable’ module, or if there is an issue with the Python installation or environment.

More specifically, Python 3.10 removed the ‘iterable’ abstract class from the ‘collections’ module.

Now, the iterable class can be imported from ‘collections.abc’ instead of ‘collections’.

How to fix this cannot import name ‘iterable’ from ‘collections’

As mentioned above the quickest way to fix the error is to import ‘Iterable’ class from ‘collections.abc’ rather than ‘collections’.

From this import statement:

from collections import Iterable

# Use Iterable class as usual

To this import statement.

from collections.abc import Iterable

# Use Iterable class as usual

Other Solution to fix the error

Here are other solutions you can consider when the given above does not fix it.

📌 Upgrade Python

If you are using an outdated version of Python, the first solution is to upgrade to the latest version. This will ensure that your Python version supports the “iterable” module.

📌 Upgrade package

If you are using an outdated version of the “collections” package, you can upgrade it using pip, the package manager for Python.

You can use the following command to upgrade the package:

pip install --upgrade collections

📌 Uninstall conflicting packages

If you have multiple versions of the “collections” package installed in your system, you can uninstall the conflicting packages using pip.

You can use the following command to uninstall the package:

pip uninstall collections

Once you have uninstalled the conflicting packages, you can reinstall the package using the following command:

pip install collections

Anyway, here are other fixed errors you can consider when somehow you might encounter them.

Conclusion

To conclude what we have explained about “ImportError: cannot import name ‘iterable’ from collections‘” error in Python, the first thing you should do is to check your Python version and ensure that you have the latest version installed.

You should also ensure that you have the latest version of the “collections” package installed, and if you have multiple versions of the package installed, you should uninstall the conflicting packages.

I hope this article has helped you fix the error.

Until next time! 😊

Why ImportError happens on collections

collections ImportErrors are almost always from Python 3.10 removing legacy import paths that had already been deprecated. The classic: from collections import Callable fails since 3.10.

Common triggers

  • Abstract base classes moved. Callable, Iterable, Mapping, MutableMapping moved from collections to collections.abc in Python 3.3. Removed from the old location in 3.10.
  • Third-party library not yet updated. Old libraries still import from the deprecated path.
  • Typo. deque is lowercase; Deque raises ImportError.

Diagnostic pattern

# BAD (Python 3.10+)
from collections import Callable   # ImportError
from collections import Mapping    # ImportError

# GOOD — use collections.abc
from collections.abc import Callable
from collections.abc import Mapping, MutableMapping

# Common collections types (correct locations)
from collections import Counter, defaultdict, deque, OrderedDict, namedtuple
from collections.abc import Iterable, Sequence, Mapping, MutableMapping, Callable

Best practices

  • Import ABCs from collections.abc, not collections directly.
  • Upgrade legacy dependencies that fail on Python 3.10+.
  • Prefer typing.* for type hints. from typing import Callable is the modern way for annotations.
Quick step-by-step summary (click to expand)
  1. Change the import to collections.abc. Replace from collections import Iterable with from collections.abc import Iterable. That is where the ABC classes now live.
  2. Fix third-party packages that still use the old import. Upgrade the offending package with pip install –upgrade pkgname. Most maintained libraries have already fixed this.
  3. Pin Python to 3.9 if you cannot patch. The collections.Iterable alias was removed in Python 3.10. Downgrading to 3.9 is a valid short-term fix.
  4. Monkey-patch as an absolute last resort. Add import collections; import collections.abc; collections.Iterable = collections.abc.Iterable at the top of your entry file. Ugly but works.

Frequently Asked Questions

What is Python ImportError and what causes it?

ImportError is raised when an import fails for any reason. The most specific subtype is ModuleNotFoundError (no such module). Plain ImportError typically means the module exists but a name inside it can’t be imported, e.g. ‘cannot import name X from Y’ (X was renamed, removed, or moved between versions of Y). Common with library version mismatches.

How do I fix ‘cannot import name X from Y’?

Three steps: (1) Check the library version: pip show Y. (2) Check the changelog of Y, X may have been renamed or removed in a recent release. (3) Either pin to an older Y version (pip install Y==1.x.y) or update your code to the new import path. Common 2025-2026 examples: Werkzeug url_decode removed, Pillow ANTIALIAS renamed to LANCZOS.

Why does the import work in REPL but fail in script?

Two reasons. (1) Different Python interpreter: REPL uses one Python, your script uses another. Run python –version both times. (2) Different working directory: REPL is started where you have access to local modules, script is run from a different cwd. Add the project path to sys.path or use python -m to run as a module.

How do I avoid circular import errors?

Circular imports happen when module A imports B and B imports A at the top level. Three fixes: (1) Move one import inside the function that uses it (lazy import). (2) Restructure code so A and B both import from a third module C. (3) Use TYPE_CHECKING for type-hint-only imports: if TYPE_CHECKING: from a import X.

Where can I find more ImportError fixes?

Browse the ImportError reference hub for 67+ specific fixes (Flask, Werkzeug, Django, ML library versions). For missing-module cases see ModuleNotFoundError. For Python setup help see Python Tutorial hub.

Glay Eliver


Programmer & Technical Writer at PIES IT Solution

Glay Eliver is a programmer and writer at PIES IT Solution, author of over 600 tutorials at itsourcecode.com. Specializes in JavaScript tutorials, Microsoft Office how-tos (Excel, Word, PowerPoint), and Python error debugging covering ImportError, TypeError, AttributeError, ModuleNotFoundError, and JavaScript ReferenceError. Authored several of the site’s highest-traffic Excel and MS Office reference articles.

Expertise: JavaScript · MS Excel · MS Word · MS PowerPoint · Python · Python ImportError · Python TypeError · Python AttributeError · ModuleNotFoundError · JavaScript ReferenceError · Pygame
 · View all posts by Glay Eliver →