我正在尝试安装新模块,但我发现pip
不起作用 - 它显示
pkg_resources.DistributionNotFound: The 'pip==1.5.6' distribution was not found and is required by the application
我执行的每个电话。另外,对于pip --help
。我找到了一些建议,使用pip
或pip
重新安装easy_install
,但easy_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
表示要安装以下内容: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
答案 0 :(得分:0)
具有错误的完整回溯将很有用。可能导致此问题的一种情况是,安装了多个版本的Python。
例如,在我的Ubuntu 20.04.1 LTS上,除了从Ubuntu 20分发的Python 3.8之外,我还从源代码安装了Python 3.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
最后一行是有问题的错误,但请注意回溯中的一个重要细节: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)
可能遇到的另一问题是在进行pip3.6 install
时发生的missing lsb_release问题:
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
请注意,对于我发行版中的原始Python,我只使用pip3
,而不是pip3.8
。但是要使其正常工作,我需要先将当前的python切换到3.8。例如,我将执行sudo update-alternatives --config python
并选择3.8。其他人可能对managing Python versions使用不同的方法。
当心更改系统的默认Python,它可能会引起问题,包括“终端未打开”之类的症状。最好有一个备用终端,例如Visual Studio Code中的一个。