0

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?

stdcerr
  • 11,091
  • 17
  • 60
  • 107
  • 2
    You have to import using `from collections.abc import MutableMapping` instead from `from collections import MutableMapping` – Kabilan Mohanraj Jan 26 '22 at 20:49
  • 2
    side note: using the OS to upgrade Flask might be operating on a different version of Python than the 3.10 you're using. that might be the only version you have, but i think unlikely. – mechanical_meat Jan 26 '22 at 20:51
  • 1
    https://stackoverflow.com/search?q=ImportError%3A+cannot+import+name+MutableMapping+from+collections – phd Jan 26 '22 at 21:57

3 Answers3

5

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.

Ref. https://docs.python.org/3.9/library/collections.html

noraj
  • 2,818
  • 1
  • 24
  • 34
Nabil
  • 618
  • 1
  • 8
  • You advise OP to monkey-patch [`OpenBMC`](https://gerrit.openbmc-project.xyz/plugins/gitiles/openbmc/openbmc/+/d1a90aa35d35426789d8f4061166a6dd8d27a30e/poky/bitbake/lib/bb/compat.py), did I got you right? – Yevgeniy Kosmak Jan 26 '22 at 20:58
  • @YevgeniyKosmak well, yep. That's what I did, at least. I only needed to run a given software just once and that monkey-patching was way easier to do than installing a Python version prior to 3.10. – Luis Milanese May 26 '22 at 20:51
3

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
navylover
  • 10,374
  • 5
  • 24
  • 34
1

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
Kabilan Mohanraj
  • 1,508
  • 1
  • 6
  • 16