Siddhesh Khadapkar
Siddhesh Khadapkar

Reputation: 196

Inltk setup "ImportError: cannot import name 'Iterable' from 'collections' (C:\Program Files\Python311\Lib\collections\__init__.py)"

While using iNltk package i ran into this error ImportError: cannot import name 'Iterable' from 'collections' (C:\Program Files\Python311\Lib\collections\__init__.py)

I was trying to setup the hindi language

from inltk.inltk import setup
setup('hi')

Upvotes: 0

Views: 2494

Answers (1)

Siddhesh Khadapkar
Siddhesh Khadapkar

Reputation: 196

I was getting this error because the Iterable abstract class was removed from the collections module in Python 3.10. The inltk package is still using the old version of the collections module, which is why you are getting the error.

There are a few ways to fix this error. One way is to upgrade the inltk package to a version that is compatible with Python 3.10. Another way is to manually import the Iterable class from the collections.abc module.

Or you can make changes in the core file by manually importing the Iterable class. This method is temporary but will save your day.

note: recommended to make this changes if you are using venv(virtual env)

At path ..file_path..\venv\Lib\site-packages\fastai\imports\core.py

from collections import abc,  Counter, defaultdict, namedtuple, OrderedDict
from collections.abc import Iterable

make the above changes.

This will import the Iterable class from the collections.abc module, which will allow you to use the inltk package without getting the error.

Another way to fix this error is to downgrade your Python installation to Python 3.9. However, this is not always an option, as some software may not be compatible with Python 3.9.

Upvotes: 0

Related Questions