DistributionNotFound error after upgrading pip
Asked Answered
P

8

10

In reading about virtualenv here I realized I didn't have pip 1.3+, so I ran pip install --upgrade pip and now when I run pip --version i get the following:

Traceback (most recent call last):
  File "/usr/local/bin/pip", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py", line 2807, in <module>
    parse_requirements(__requires__), Environment()
  File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py", line 594, in resolve
    raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: pip==1.2.1

If it helps, or is at all relevant, my $PATH looks like this:

/usr/local/bin:/usr/local/share/python:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin

Also, which pip gives me /usr/local/bin/pip.

Not sure what to do about the error. Thanks.

Purine answered 20/3, 2013 at 1:45 Comment(0)
G
21

The brutal way:

Assuming you are using homebrew for Mac (because I see /usr/local/Cellar), I suggest to

  • remove (or backup) /usr/local/lib/python2.7, and
  • brew rm python && brew install python.

This will definitely install pip 1.3.3 alongside of python. Your distribute will also be 0.6.35.

The soft way:

From /usr/local/lib/python2.7/site-packages just remove:

  • easy-install.pth
  • pip-1.2.1-py2.7.egg or other versions of pip you have.
  • distribute-0.6.34-py2.7.egg or other versions

Then, brew rm python && brew install python. This will leave all your other bindings from brew and installed stuff intact. Python, pip and distribute will be replaced with up-to-date versions.

additionally:

Please check that you don't have a distribute or setuptools or pip located in /Library/Python/2.7/site-packages. That dir is re-used by all python 2.7 versions (brewed or from OS X) and will interferre with the pip/distribute already installed by Homebrew.

Galumph answered 22/3, 2013 at 8:40 Comment(3)
ls -a, after cd-ing into /Library/Python/2.7/site-packages gives me only three files: ., .., and README. So I guess I'm good on that front.Purine
alright, then you did not make sudo easy_install pip which is good.Galumph
Why was this necessary? Is there a related issue filed against homebrew?Hiawatha
C
10

I happened to get to a similar state after upgrading from OS X Lion to Mountain Lion today.

The other proposed solutions either do not work, or replace the Apple version of Python with the brew version, which I'm not sure is what saclark asked for.

What I did to get it fixed is install distribute manually, thus getting easy_install back to work, and then install pip with it.

The commands are:

$ curl -O http://pypi.python.org/packages/source/d/distribute/distribute-0.6.45.tar.gz
$ tar -xzvf distribute-0.6.45.tar.gz
$ cd distribute-0.6.45
$ sudo python setup.py install
$ sudo easy_install pip

If the link does not work, you can alway find newer versions of distribute here.

Chancellor answered 2/6, 2013 at 14:38 Comment(1)
This worked for me and it is a lot simpler than the other answer to brew rm python && brew install python—thanks!Lindgren
S
7

I got similar problem today. After some research, I solved it by reinstalling pip using this:-

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

Hope somebody would find it helpful.

Seedbed answered 8/4, 2015 at 1:45 Comment(1)
This helped me when I had just installed Python 3.12 on a system (WSL Ubuntu 20.04) with 3.8. I made sure to run sudo update-alternatives --install /usr/local/bin/python python /usr/bin/python3.12 2 first. I ran it with sudo so that it would exist in (my) PATH and not just /usr/MYNAME/.local/bin.Hedjaz
C
4

As an aside, there's an easier way to do it (I just encountered this).

Edit /usr/local/bin/pip and change the references to version number (so below you'd want to change '1.5.6' to whatever version number you're using):

#!/usr/local/opt/python/bin/python2.7
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==1.5.6','console_scripts','pip'
__requires__ = 'pip==1.5.6'
import sys
from pkg_resources import load_entry_point

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

then you may be completely good at that point.

Cobos answered 4/9, 2014 at 6:44 Comment(1)
All other answers above failed for me, this worked! Thanks Jeff.Noteworthy
G
2

I wanna find out at where pip 1.2.1 is required, but I don't have so much time... so I just downgrade pip to 1.2.1. It can't be helped for a while, till pip or distribute package is modified.

How to do this? just type this in console(I hope your distribute package is well):

easy_install pip==1.2.1
Gracielagracile answered 29/3, 2013 at 23:57 Comment(0)
M
2

There is no need to uninstall python and install it back. Get the latest distribute package installed and then update pip with it should do the trick.

wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
sudo python ez_setup.py
sudo easy_install -U pip
Maller answered 24/10, 2013 at 14:26 Comment(0)
V
1

The correct way to fix modern version (6.x) of pip in 2 steps

  1. Delete the pip package in Python's site-package. For Homebrew Python 2.7, do this:

    rm -r /usr/local/lib/python2.7/site-packages/pip
    
  2. Follow the instructions on the official pip documentation site to reinstall it. For short:

    curl -O https://bootstrap.pypa.io/get-pip.py
    python get-pip.py
    

For pip 6.x, there's no need to install the legacy distribute package. Just setuptools, which will be installed by default via the get-pip.py script mentioned above.

Vitellus answered 28/4, 2015 at 3:57 Comment(0)
S
0

Hm.. puzzling. Wonder where that 1.2.1 comes from. Just out of curiosity, could you post the contents of /usr/local/bin/pip? Should only be a couple of lines.

You could try updating pip (again) with distribute, and maybe also distribute itself..

easy_install --upgrade distribute
easy_install --upgrade pip
Subdebutante answered 21/3, 2013 at 15:44 Comment(3)
If I'm not mistaken, I believe 1.2.1 is the version of pip I had before running pip install --upgrade pip. nano /usr/local/bin/pip gives me: #!/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/Resou$ # EASY-INSTALL-ENTRY-SCRIPT: 'pip==1.2.1','console_scripts','pip' __requires__ = 'pip==1.2.1' import sys from pkg_resources import load_entry_point if __name__ == '__main__': sys.exit( load_entry_point('pip==1.2.1', 'console_scripts', 'pip')() )Purine
Here are links which may help solve the issue (Im hesitant to try anything without knowing for sure what Im doing): pip broke; -- homebrew python issue; -- cant use pip; -- using pip w/ homebrew python; -- homebrew/distributionnotfound errorPurine
Apparently the pip --upgrade pip did for some reason not upgrade pip. I don't think there is any danger in executing the easy_install commands in my reply. If all else fails, you could also just reinstall /re-brew python (brew rm python, then brew install python).Subdebutante

© 2022 - 2024 — McMap. All rights reserved.