gpt4 book ai didi

python pip 错误 pkg_resources.DistributionNotFound

转载 作者:行者123 更新时间:2023-12-04 18:02:35 31 4
gpt4 key购买 nike

我正在尝试安装一个新模 block ,但我发现 pip不起作用 - 它显示

pkg_resources.DistributionNotFound: The 'pip==1.5.6' distribution was not found and is required by the application

对于我执行的每个电话。另外,对于 pip --help .我找到了一些重新安装的建议 pip使用 pipeasy_install ,但是 easy_install也不起作用:
pkg_resources.DistributionNotFound: The 'setuptools==5.7' distribution was not found and is required by the application

有没有办法在不重新安装的情况下解决这个问题 python及其所有模 block ?
我有 Linux Ubuntu 14.04。 apt-get install python-pip建议安装 pip (以及一堆其他以下软件)就像我的系统中没有它一样。我不敢这样做,这里会发生冲突吗?

更新。 apt-get说它要安装以下内容: build-essential dpkg-dev fakeroot g++ g++-4.8 libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libfakeroot libstdc++-4.8-dev python-chardet-whl python-colorama python-colorama-whl python-distlib python-distlib-whl python-html5lib python-html5lib-whl python-pip python-pip-whl python-requests-whl python-setuptools python-setuptools-whl python-six-whl python-urllib3-whl python-wheel .但据我所知 pip 在没有这些包的情况下对我有用。
我也表演了 which -a python : /usr/bin/python which -a pip : /usr/local/bin/pip python --version : Python 2.7.6

最佳答案

拥有错误的完整回溯会很有用。可能导致此问题的一种情况是安装了多个版本的 Python。
例如,在我的 Ubuntu 20.04.1 LTS 上,除了随 Ubuntu 20 一起分发的 Python 3.8 之外,我还从源代码安装了 Python 3.6。这就是我用 pip3 --version 得到的结果。安装 Python 3.6 后:

Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 581, in _build_master
ws.require(__requires__)
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 898, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 789, in resolve
raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.VersionConflict: (pip 20.2.3 (/usr/local/lib/python3.6/site-packages), Requirement.parse('pip==20.0.2'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/bin/pip3", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3126, in <module>
@_call_aside
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3110, in _call_aside
f(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3139, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 583, in _build_master
return cls._build_from_requirements(__requires__)
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 596, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 784, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pip==20.0.2' distribution was not found and is required by the application
最后一行是有问题的错误,但请注意回溯中的一个重要细节: raise VersionConflict .
这可以通过 explicitly using 解决 pip 所需的版本:
$ python3.6 -m pip --version
pip 20.2.3 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
或者干脆:
$ pip3.6 --version
pip 20.2.3 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
另一个可能会遇到的问题是 missing lsb_release做时的问题 pip3.6 install :
  File "/usr/local/lib/python3.6/subprocess.py", line 438, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 1.
这可以通过定位 lsb_release.py 来解决。并创建符号链接(symbolic link),例如:
sudo ln -s /usr/lib/python3/dist-packages/lsb_release.py /usr/local/lib/python3.6/site-packages/lsb_release.py
现在可以升级 pip3.6 并安装新软件包:
$ pip3.6 install --upgrade pip
$ pip3.6 install mypy
managing Python versions有不同的方法.小心使用类似 sudo update-alternatives --config python 的东西.更改系统的默认 Python 可能会导致问题,包括终端未打开等症状。最好有一个备用终端,例如 Visual Studio Code 中的终端。

关于python pip 错误 pkg_resources.DistributionNotFound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32693107/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com