简体   繁体   English

pip 坏了。 如何修复 DistributionNotFound 错误?

[英]pip broke. how to fix DistributionNotFound error?

Whenever i try to use pip I get an error.每当我尝试使用 pip 时,我都会收到错误消息。 For exampple:例如:

$ sudo pip install gevent-websocket

Traceback (most recent call last):  
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2675, in <module>
parse_requirements(__requires__), Environment()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 552, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: pip==0.8.1

I feel tempted to change the value of into pip==0.8.2.. but I dont feel dealing with the consequences of 'hacking' up my installation... I'm running python 2.7 and pip is at version 0.8.2.我很想将值更改为 pip==0.8.2.. 但我不觉得要处理“破解”我的安装的后果...我正在运行 python 2.7 和 pip 版本为 0.8.2。

I find this problem in my MacBook, the reason is because as @Stephan said, I use easy_install to install pip, and the mixture of both py package manage tools led to the pkg_resources.DistributionNotFound problem.我在我的 MacBook 中发现了这个问题,原因是因为正如@Stephan 所说,我使用easy_install安装 pip,而 py package 管理工具的混合导致了pkg_resources.DistributionNotFound问题。 The resolve is:解决办法是:

easy_install --upgrade pip

Remember: just use one of the above tools to manage your Py packages.请记住:只需使用上述工具之一来管理您的 Py 包。

I replaced 0.8.1 in 0.8.2 in /usr/local/bin/pip and everything worked again.我在 /usr/local/bin/pip 中的 0.8.2 中替换了 0.8.1,一切都恢复正常了。

__requires__ = 'pip==0.8.2'
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('pip==0.8.2', 'console_scripts', 'pip')()
    )

I installed pip through easy_install which probably caused me this headache.我通过easy_install安装了pip,这可能让我很头疼。 I think this is how you should do it nowadays..我认为这就是你现在应该这样做的方式..

$ sudo apt-get install python-pip python-dev build-essential 
$ sudo pip install --upgrade pip 
$ sudo pip install --upgrade virtualenv

I had this issue when I was using homebrew.我在使用自制软件时遇到了这个问题。 Here is the solution from Issue #26900这是问题#26900的解决方案

python -m pip install --upgrade --force pip

Try re-installing with the get-pip script:尝试使用 get-pip 脚本重新安装:

wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py

This is sourced from the pip Github page, and worked for me.这来自 pip Github 页面,为我工作。

If you're on CentOS make sure you have the YUM package "python-setuptools" installed如果您使用的是 CentOS,请确保您安装了 YUM package “python-setuptools”

yum install python-setuptools

Fixed it for me.为我修好了。

The root of the problem are often outdated scripts in the bin (Linux) or Scripts (Windows) subdirectory.问题的根源通常是bin (Linux) 或Scripts (Windows) 子目录中的过时脚本。 I'll explain this using problem I encountered myself as an example.我将使用我自己遇到的问题作为示例来解释这个问题。

I had virtualenv version 1.10 installed in my user site-packages (the fact it's in user site-packages not sytem site-packages is irrelevant here)我在我的用户站点包中安装了 virtualenv 1.10 版(它在用户站点包而不是系统站点包中的事实在这里无关紧要)

pdobrogost@host:~$ which virtualenv
/home/users/pdobrogost/.local/bin/virtualenv
pdobrogost@host:~$ virtualenv --version
1.10

After I upgraded it to version 1.11 I got the following error:将其升级到 1.11 版后,出现以下错误:

pdobrogost@host:~$ virtualenv --version  
Traceback (most recent call last):   
  File "/home/users/pdobrogost/.local/bin/virtualenv", line 5, in <module>
    from pkg_resources import load_entry_point   
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 2701, in <module>
    return self.__dep_map   
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 572, in resolve
    if insert: 
pkg_resources.DistributionNotFound: virtualenv==1.10

File /home/users/pdobrogost/.local/bin/virtualenv mentioned in the error message looked like this:错误消息中提到的文件/home/users/pdobrogost/.local/bin/virtualenv如下所示:

#!/opt/python/2.7.5/bin/python2.7
# EASY-INSTALL-ENTRY-SCRIPT: 'virtualenv==1.10','console_scripts','virtualenv'
__requires__ = 'virtualenv==1.10'
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('virtualenv==1.10', 'console_scripts', 'virtualenv')()
    ) 

There, we see that virtualenv script was not updated and still requires previously installed version 1.10 of virtualenv.在那里,我们看到virtualenv脚本没有更新,仍然需要以前安装的 virtualenv 1.10 版本。
Now, reinstalling virtualenv like this现在,像这样重新安装 virtualenv

pdobrogost@host:~$ pip install --user --upgrade virtualenv
Downloading/unpacking virtualenv from https://pypi.python.org/packages/py27/v/virtualenv/virtualenv-1.11.1-py27-none-any.whl#md5=265770b61de41d34d2e9fdfddcdf034c
  Using download cache from /home/users/pdobrogost/.pip_download_cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fpy27%2Fv%2Fvirtualenv%2Fvirtualenv-1.11.1-py27-none-any.whl
Installing collected packages: virtualenv
Successfully installed virtualenv
Cleaning up...

does not help (neither pip install --user --upgrade --force-reinstall virtualenv ) because script /home/users/pdobrogost/.local/bin/virtualenv is left unchanged.没有帮助( pip install --user --upgrade --force-reinstall virtualenv )因为脚本/home/users/pdobrogost/.local/bin/virtualenv保持不变。

The only way I could fix this was by manually removing virtualenv* scripts from /home/users/pdobrogost/.local/bin/ folder and installing virtualenv again.我可以解决此问题的唯一方法是从/home/users/pdobrogost/.local/bin/文件夹中手动删除 virtualenv* 脚本并再次安装 virtualenv。 After this, newly generated scripts refer to the proper version of the package:在此之后,新生成的脚本引用 package 的正确版本:

pdobrogost@host:~$ virtualenv --version
1.11

I was able to resolve this like so:我能够像这样解决这个问题:

$ brew update
$ brew doctor
$ brew uninstall python
$ brew install python --build-from-source    # took ~5 mins
$ python --version                           # => Python 2.7.9
$ pip install --upgrade pip

I'm running w/ the following stuff (as of Jan 2, 2015):我正在运行以下内容(截至 2015 年 1 月 2 日):

OS X Yosemite
Version 10.10.1

$ brew -v
Homebrew 0.9.5

$ python --version
Python 2.7.9

$ ipython --version
2.2.0

$ pip --version
pip 6.0.3 from /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.3-py2.7.egg (python 2.7)

$ which pip
/usr/local/bin/pip

I was facing the similar problem in OSx.我在 OSx 中遇到了类似的问题。 My stacktrace was saying我的堆栈跟踪说

raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: setuptools>=11.3

Then I did the following然后我做了以下

sudo pip install --upgrade setuptools

This solved the problem for me.这为我解决了这个问题。 Hope someone will find this useful.希望有人会发现这很有用。

On Mac OS X (MBP), the following (taken from another answer found herein) resolved my issues:在 Mac OS X (MBP) 上,以下(取自此处找到的另一个答案)解决了我的问题:

C02L257NDV33:~ jjohnson$ brew install pip
Error: No available formula for pip
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can:
    sudo easy_install pip
C02L257NDV33:~ jjohnson$ sudo easy_install pip

Clearly the root cause here is having a secondary method by which to install python (in my case Homebrew).显然,这里的根本原因是有一种安装 python 的辅助方法(在我的情况下是 Homebrew)。 Hopefully, the people responsible for the pip script can remedy this issue since its still relevant 2 years after first being reported on Stack Overflow.希望负责 pip 脚本的人员能够解决这个问题,因为它在 Stack Overflow 上首次报告 2 年后仍然相关。

I had this problem because I installed python/pip with a weird ~/.pydistutils.cfg that I didn't remember writing.我遇到了这个问题,因为我用一个奇怪的~/.pydistutils.cfg安装了 python/pip,我不记得写了。 Deleted it, reinstalled (with pybrew ), and everything was fine.删除它,重新安装(使用pybrew ),一切都很好。

In my case (sam problem, but other packages) there was no version dependency.就我而言(sam 问题,但其他软件包)没有版本依赖性。 A sequence of pip uninstall and pip insstall did help.一系列 pip 卸载和 pip 安装确实有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM