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

qyuhtwio  于 2023-04-22  发布在  Python
关注(0)|答案(5)|浏览(562)

嘿,我已经在我的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'

这在python3.9中工作正常,但当我更新到3.10时,我开始得到这个错误。我该如何解决这个问题?

eyh26e7m

eyh26e7m1#

问题是由旧版本的pyparsing引起的,该版本已被出售到pkg_resources中,现在是setuptools的一部分。
我认为如果你安装一个更新的setuptools,事情会运行得更好:

python -m pip install -U setuptools

编辑-在Ubuntu 18.04上安装了我自己的3.10.1版本后,我遇到了同样的问题。损坏的pkg_resources阻止了任何更新,所以你的经典Catch-22。为了开始寻找解决方案,我已经在setuptools Github repo上提交了一个工单。
EDIT 2-基于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。

q7solyqu

q7solyqu2#

使用下面的代码更新pip

curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
lpwwtiir

lpwwtiir3#

我可以尝试用pip install request --upgrade修复它

avkwfej4

avkwfej44#

“不要从apt安装pipenv,它太旧了。从pypi安装。”来源:https://github.com/pypa/pipenv/issues/5469
这为我解决了:

sudo apt remove pipenv
pip install pipenv

不幸的是,pipenv在这个控制台中没有开箱即用。我不得不用途:

python -m pipenv

或者只是启动一个新的终端会话。

kmynzznz

kmynzznz5#

更新pip...collections。MutableMapping已变为collections.abc.MutableMapping。

相关问题