18

I am using pip on EC2 now, python version is 2.7. 'sudo pip' suddenly doesn't work anymore.

[ec2-user@ip-172-31-17-194 ~]$ sudo pip install validate_email
Traceback (most recent call last):
  File "/usr/bin/pip", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3138, in <module>
    @_call_aside
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3124, in _call_aside
    f(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3151, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 663, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 676, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 849, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pip==6.1.1' distribution was not found and is required by the application
[ec2-user@ip-172-31-17-194 ~]$ which pip
/usr/local/bin/pip
MattDMo
  • 100,794
  • 21
  • 241
  • 231
Marshall X
  • 784
  • 1
  • 5
  • 17
  • 22
    It seems that `sudo pip` called /usr/bin/pip, not /usr/local/bin/pip, because of PATH environment variables for root user, so you may try `sudo /usr/local/bin/pip`. – Cissoid Jan 12 '16 at 02:12
  • Possible duplicate of [Broken pip3 and easy_install3: DistributionNotFound](http://stackoverflow.com/questions/30288404/broken-pip3-and-easy-install3-distributionnotfound) or maybe not. pip3 != pip right? – Dimitri Podborski Jan 12 '16 at 02:15

4 Answers4

13

first, which pip is not going to return the same result as sudo which pip, so you should check that out first.

you may also consider not running pip as sudo at all. Is it acceptable & safe to run pip install under sudo?

second, can you try this:

easy_install --upgrade pip

if you get an error here (regarding pip's wheel support), try this, then run the above command again:

easy_install -U setuptools
wesm
  • 451
  • 6
  • 14
6

I fixed the same error ("The 'pip==6.1.1' distribution was not found") by using the tip of Wesm :

$> which pip && sudo which pip
/usr/local/bin/pip
/usr/bin/pip

So, it seels that "pip" of average user and of root are not the same. Will fix it later.

Then I ran "sudo easy_install --upgrade pip" => succeed

Then I used "sudo /usr/local/bin/pip install " and it works.

JayMore
  • 211
  • 5
  • 8
3

Some additional information for anyone who is also stuck on the same issue:-

Running commands with sudo searches for the command in usr/bin directory. One way to solve this issue is to specify the complete path to the command while using sudo as commented by @Cissoid in the question's comment section

Or

...what you can do is create a symbolic link(sym link) to that command in the usr/bin directory using ln command.

$> ln -s /usr/local/bin/pip /usr/bin/pip

The syntax is:-

$> ln -s /path/to/file /path/to/link 
0

I tried a few of these solutions without much success. In the end I just created a new instance using Ubuntu as the operating system. It was already setup properly for using Python properly.

If that is not possible then you can try linking the user pip into a folder on root's (sudo) path.

Martlark
  • 14,208
  • 13
  • 83
  • 99