python pip错误pkg_resources.DistributionNotFound
我试图安装一个新模块,但我发现python pip错误pkg_resources.DistributionNotFound,python,pip,reinstall,Python,Pip,Reinstall,我试图安装一个新模块,但我发现pip不起作用-它显示了这一点 pkg_resources.DistributionNotFound: The 'pip==1.5.6' distribution was not found and is required by the application 对于我执行的每个呼叫。另外,对于pip--help。我发现一些建议是使用pip或easy\u install重新安装pip,但是easy\u install也不起作用: pkg_resources.Dist
pip
不起作用-它显示了这一点
pkg_resources.DistributionNotFound: The 'pip==1.5.6' distribution was not found and is required by the application
对于我执行的每个呼叫。另外,对于pip--help
。我发现一些建议是使用pip
或easy\u install
重新安装pip
,但是easy\u install
也不起作用:
pkg_resources.DistributionNotFound: The 'setuptools==5.7' distribution was not found and is required by the application
有没有办法在不重新安装python及其所有模块的情况下解决此问题?我有Linux Ubuntu 14.04。
apt get install python pip
建议安装pip
(以及下面的一堆软件),就像我的系统中没有它一样。我害怕这样做,这里会有冲突吗
Upd.apt get
表示希望安装以下内容:构建基本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 whl python-html5lib python-whl pythonpython-pip-python-pip-whl-python请求whl-python设置工具python设置工具whl-python六个whl-python-urlib3-whl-python轮子
。但据我所知,皮普在没有这些软件包的情况下为我工作。我还表演了
which-a python
:/usr/bin/python
which-a pip
:/usr/local/bin/pip
python--version
:python2.7.6
获取错误的完整回溯信息会很有用。可能导致此问题的一个场景是安装了多个版本的Python
例如,在我的Ubuntu20.04.1 LTS上,除了随Ubuntu20发布的Python3.8之外,我还从源代码安装了Python3.6。这是我在安装Python 3.6后通过pip3--version
得到的:
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
或者简单地说:
$ pip3.6 --version
pip 20.2.3 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
您可能会遇到的另一个问题是执行pip3.6安装时的问题:
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
并创建符号链接来解决,例如:
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
有不同的方法来解决这个问题。小心使用类似于
sudo-updatealternations--config-python
的东西。更改系统的默认Python可能会导致问题,包括终端未打开等症状。最好有一个备份终端,比如Visual Studio代码中的备份终端。请在您的问题中包括which-a python
和which-a pip
的输出。另外,您可能希望更具体地了解由apt get install python pip
拉入的软件包,但您不希望在您的系统上安装这些软件包。我之前编辑了我的问题是的,但您没有真正回答我的问题。以下哪一项对你有问题?基本上你有两个很好的选择:1)接受,ubuntu的安装量超过了运行pip所需的最低限度。2) 切换到virtualenv,因此避免使用apt
安装python依赖项。您可能还想阅读我的答案,其中将解释为什么pip
安装对您不起作用。请注意,我建议不要使用pip
安装到/usr/bin/python
中。好的,我已经通过apt get安装了pip
,并且。。。没有什么变化。我仍然无法运行pip
,也无法接收错误
$ pip3.6 install --upgrade pip
$ pip3.6 install mypy