'cannot import name 'MutableMapping' from 'collections' [duplicate]
I'm getting the following error:
File "/home/ron/rzg2l_bsp_v1.3/poky/bitbake/lib/bb/compat.py", line 7, in <module>
from collections import MutableMapping, KeysView, ValuesView, ItemsView, OrderedDict
ImportError: cannot import name 'MutableMapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
and Googling revealed that flask has to be >=2.0, so I did
$ sudo pacman -Syu python-flask
which installed version (2.0.2-3
)
which did not resolve the issue. Further searching revealed that babelfish needs to be upgraded too, so I did:
$ python3.10 -m pip install babelfish -U
which showed me:
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: babelfish in /home/ron/.local/lib/python3.10/site-packages (0.6.0)
Collecting babelfish
Using cached babelfish-0.6.0-py3-none-any.whl (93 kB)
Downloading babelfish-0.5.5.tar.gz (90 kB)
|████████████████████████████████| 90 kB 406 kB/s
but I'm still getting the same error. Can anyone tell what else I'm missing?
Solution 1:[1]
You need to import collection.abc
Here the link to doc
>>> from collections import MutableMapping
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'MutableMapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
>>> from collections.abc import MutableMapping
Deprecated since version 3.3, will be removed in version 3.10: Moved Collections Abstract Base Classes to the collections.abc module. For backwards compatibility, they continue to be visible in this module through Python 3.9.
Solution 2:[2]
If you have more than one interpreter, use:
import sys
if sys.version_info[:2] >= (3, 8):
from collections.abc import MutableMapping
else:
from collections import MutableMapping
Solution 3:[3]
The direct import has been deprecated since Python 3.3 and will stop working in Python 3.9. You need to import using
from collections.abc import MutableMapping
This is the deprication warning I got
DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | noraj |
Solution 2 | |
Solution 3 | Kabilan Mohanraj |