获取 AttributeError:在 Linux Python 3.10 上使用任何 pip3 命令时,模块“collections”没有属性“MutableMapping”

新手上路,请多包涵

嘿,我已经在我的 linux (Zorin os lite 15.3 X64) 机器上安装了最新的 python 3.10 和 pip3,但是每当我尝试使用任何 pip3 命令时,我都会收到以下错误例如我使用命令:

pip3冻结

我收到以下错误:

 Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
  File "/usr/lib/python3/dist-packages/pip/__init__.py", line 22, in <module>
    from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 73, in <module>
    vendored("pkg_resources")
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 33, in vendored
    __import__(modulename, globals(), locals(), level=0)
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 77, in <module>
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/_vendor/packaging/requirements.py", line 9, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 672, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 632, in _load_backward_compatible
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/extern/__init__.py", line 43, in load_module
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/_vendor/pyparsing.py", line 943, in <module>
AttributeError: module 'collections' has no attribute 'MutableMapping'

这在 python 3.9 上运行良好,但是当我更新到 3.10 时,我开始收到此错误。我该如何解决这个问题?

原文由 Aditya Yadav 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 684
1 个回答

问题是由旧版本的 pyparsing 引起的,它已被销售到 pkg_resources ,现在是 setuptools 的一部分

我想如果你安装一个更新的 setuptools ,事情会运行得更好:

 python -m pip install -U setuptools

编辑 - 在 Ubuntu 18.04 上安装我自己的 3.10.1 版本后,我遇到了同样的问题。损坏的 pkg_resources 阻止进行任何更新,因此您的经典 Catch-22。为了开始寻求解决方案,我在 setuptools Github 存储库上提交了一张票。

EDIT2 - 基于对 setuptools GitHub repo 的帮助,我执行了以下步骤:

 # add deadsnake repo (default or nightly)
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.10
git clone https://github.com/pypa/setuptools.git && cd setuptools && sudo python3.10 setup.py install
sudo apt install python3.10-distutils
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
sudo apt install python3.10-venv

此时,我可以在 Python3.10 中运行 pip,并使用 python3.10 -m venv virtualenv-dir 创建 venvs。

原文由 PaulMcG 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题