156

Whenever i try to use pip I get an error. 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.

Stephan
  • 3,679
  • 3
  • 25
  • 42
  • Lots if pain here. The simple generic solution is to download the pip installed from: [https://bootstrap.pypa.io/get-pip.py](https://bootstrap.pypa.io/get-pip.py) and then run that file (using python). The other fixes are very system dependent and generally messy and the suggestions below often don't work (based on my experience on two different kids of system) – GregD Apr 28 '19 at 15:16

11 Answers11

256

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. The resolve is:

easy_install --upgrade pip

Remember: just use one of the above tools to manage your Py packages.

Jens
  • 8,423
  • 9
  • 58
  • 78
NewPtone
  • 3,075
  • 1
  • 17
  • 10
  • 58
    Ha this just gives me the error: `pkg_resources.DistributionNotFound: distribute==0.6.36` – Timmmm Sep 15 '13 at 15:35
  • 2
    Works great on Mac OS X 10.9 as well. Thanks! – Anton Babenko Oct 23 '13 at 16:56
  • 2
    You might find that a) you need to sudo easy_install --upgrade pip and b) you might then get errors about wheel when you use pip. At that point look at this: http://stackoverflow.com/questions/20905350/latest-pip-fails-with-requires-setuptools-0-8-for-dist-info – mchicago Jan 17 '14 at 22:23
  • @PiotrDobrogost I kind of disagree - the article you have linked is about using virtualenv otherwise you have a bazillion packages and performance and conflicts between applications may occur - in this instacnce, we *want* to use virtualenv. However, to install virtualenv, you want to install it globally for everyone, and hence, sudo easyinstall. *for the virtualenv installation*. which allows virtualenv to actually work, so how else to install virtual env without doing a manual (and therefore difficult to maintain) installation. – mchicago Feb 12 '14 at 10:36
  • how to upgrade pip3 ? – pavan May 05 '14 at 08:00
  • 1
    got ..'sudo easy_install3 --upgrade pip' made it – pavan May 05 '14 at 08:05
  • Same here, but with 'sudo easy_install-2.7', corresponding to the native Mac version of Python I'm running. – Michiel Kauw-A-Tjoe Aug 26 '14 at 18:04
  • Fixed "ImportError: No module named 'pip'" after a failed pip --upgrade pip on Windows 7 – seeker Feb 03 '16 at 10:14
  • Processing pip error: Not a recognized archive type: pip,it not worked – 刘新宇 Jun 02 '17 at 09:23
31

I replaced 0.8.1 in 0.8.2 in /usr/local/bin/pip and everything worked again.

__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. 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
Stephan
  • 3,679
  • 3
  • 25
  • 42
  • 13
    I always try to avoid install pure python packages using OS package managers - and I recommend you to do the same. Ubuntu/Debian once broke the setuptools package and it caused some headaches because people could not uninstall packages using pip (due to their changes). – Hugo Lopes Tavares Jun 02 '11 at 12:51
  • using apt or yum are not agnostic enough! the strategies on this page are adequate for local development, but please please do not do this for deployments. – ken Jul 26 '12 at 14:20
  • Same here, pip killed itself when upgrading to 1.3.1 on a Mac, while pip itself mentioned it still was 1.2.1 ... – Anthony Liekens Apr 15 '13 at 09:07
  • @PiotrDobrogost please see comment above - its needed in this instance to get virtualenv to work. – mchicago Feb 12 '14 at 10:36
29

I had this issue when I was using homebrew. Here is the solution from Issue #26900

python -m pip install --upgrade --force pip
KetZoomer
  • 2,701
  • 3
  • 15
  • 43
Louis Cremen
  • 764
  • 7
  • 12
  • It might be helpful to try that both with the --user option and without (the latter requiring sudo). – Ray Oct 09 '19 at 14:25
13

Try re-installing with the get-pip script:

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.

pavan
  • 3,225
  • 3
  • 25
  • 29
7

If you're on CentOS make sure you have the YUM package "python-setuptools" installed

yum install python-setuptools

Fixed it for me.

Dave Lancea
  • 1,669
  • 1
  • 16
  • 19
6

The root of the problem are often outdated scripts in the bin (Linux) or Scripts (Windows) subdirectory. 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)

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:

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:

#!/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.
Now, reinstalling virtualenv like this

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.

The only way I could fix this was by manually removing virtualenv* scripts from /home/users/pdobrogost/.local/bin/ folder and installing virtualenv again. After this, newly generated scripts refer to the proper version of the package:

pdobrogost@host:~$ virtualenv --version
1.11
Piotr Dobrogost
  • 41,292
  • 40
  • 236
  • 366
6

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):

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
hernamesbarbara
  • 6,850
  • 3
  • 26
  • 25
6

I was facing the similar problem in 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.

Nabin
  • 11,216
  • 8
  • 63
  • 98
2

On Mac OS X (MBP), the following (taken from another answer found herein) resolved my issues:

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). 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.

Joe Johnson
  • 1,814
  • 16
  • 20
1

I had this problem because I installed python/pip with a weird ~/.pydistutils.cfg that I didn't remember writing. Deleted it, reinstalled (with pybrew), and everything was fine.

polm23
  • 14,456
  • 7
  • 35
  • 59
1

In my case (sam problem, but other packages) there was no version dependency. A sequence of pip uninstall and pip insstall did help.

rhoerbe
  • 463
  • 1
  • 4
  • 17