无法从 'collections' 导入名称 'MutableMapping'

cannot import name 'MutableMapping' from 'collections'

我收到以下错误:

  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)

Google 显示 flask 必须 >=2.0,所以我做到了

$ sudo pacman -Syu python-flask

哪个安装版本(2.0.2-3)

未能解决问题。进一步搜索发现babelfish也需要升级,所以我做了:

$ python3.10 -m pip install babelfish -U

向我展示了:

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

但我仍然遇到同样的错误。谁能告诉我还缺少什么?

您需要导入 collection.abc

这里是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

从 Python 3.3 开始,直接导入已被弃用,并将在 Python 3.9 中停止工作。您需要使用

导入
from collections.abc import MutableMapping

这是我收到的剥夺警告

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

如果您有不止一名口译员,请使用:

import sys

if sys.version_info[:2] >= (3, 8):
    from collections.abc import MutableMapping
else:
    from collections import MutableMapping