Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'pip==9.0.1' distribution was not found and is required by the application

I think my pip is broken. I've tried everything from doing force reinstall to update everything but nothing seems to work.

when I do pip2 -v then I get the following:

Traceback (most recent call last):
  File "/usr/local/bin/pip2", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3144, in <module>
    @_call_aside
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3128, in _call_aside
    f(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3157, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 666, in _build_master
    ws.require(__requires__)
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 984, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 870, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pip==9.0.1' distribution was not found and is required by the application

when I do pip -v then I get the following:

Traceback (most recent call last):
  File "/bin/pip", line 7, in <module>
    from pip._internal import main
ImportError: No module named pip._internal

FYI: I'm on Mac OSX and am using Python 2.7.14

Please help!!

like image 690
user10096621 Avatar asked Jul 18 '18 01:07

user10096621


1 Answers

Since you're on macOS, your computer already had a Python 2.7, pre-installed by Apple. If you're on macOS 10.13, it's 2.7.10; older versions of course have older versions.

Meanwhile, you've installed Python 2.7.14. You didn't tell us how—python.org installer, Anaconda, Homebrew, whatever—but that's fine.

The problem is that the Apple Python 2.7.10 is still your "primary" 2.7, so you somehow ended up with a pip 9.0.1 that installed its packages for your 2.7.14, but thinks it's supposed to run with the Apple 2.7.10 instead. That's why it's looking in /usr/local/lib/python2.7/site-packages, which is the site-packages for Apple's 2.7.10, not for your 2.7.14. And you either don't have pip for the Apple 2.7.10, or have an older version. Hence the error.


Headaches in dealing with multiple Python installations—especially multiple installations of the same version—are why the Python Packaging User Guide suggests that you:

  • Use python -m pip to run pip.
  • Use virtual environments if at all possible.

I don't know how you normally make sure you're running your 2.7.14 instead of Apple's 2.7.10, but whatever command you run, if you do the same thing with a -m pip, it's guaranteed to use your 2.7.14 rather than Apple's 2.7.10. For example, if you normally type python2, use python2 -m pip instead of pip2.

Meanwhile, if you activate a virtual environment, both python and pip (and other things like 2to3) are going to be the versions that go with that environment, no matter what else you happen to have installed and how confusing your overall system setup is.

like image 86
abarnert Avatar answered Oct 21 '22 19:10

abarnert