嘿,我已经在我的 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 时,我开始收到此错误。我该如何解决这个问题?
该问题是由旧版本的
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 存储库上的 aid,我执行了以下步骤:
# 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。
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
pip install request --upgrade
sudo apt remove pipenv
pip3 install pipenv
或者
sudo apt install pipenv