71

I wanted to update pip on my main install of Python, specifically to get the list command. Which also includes the list- updates capability.

So I ran:

sudo pip install --upgrade pip

All looked good on the install but then I went to run pip and got this: (end of install included if it helps)

Installing pip script to /usr/local/bin
    Installing pip-2.7 script to /usr/local/bin
Successfully installed pip
Cleaning up...
tom@tom-sam:~$ pip list -o
bash: /usr/bin/pip: No such file or directory
tom@tom-sam:~$ pip
bash: /usr/bin/pip: No such file or directory

Somewhat obviously I'm hosed since this is my system install of python.. I read a few answers here but have not been able to determine the easiest fix.

dartdog
  • 10,432
  • 21
  • 72
  • 121
  • Have you tried reinstalling the `python-pip` package? I believe it provides the /usr/bin/pip program. – unutbu Apr 26 '13 at 13:22
  • instead of calling "pip" did you try "pip-2.7". Sometimes it is just the symlink that is broken. – Ketouem Apr 26 '13 at 13:25
  • pip-2.7 works, how do I fix so it just gets with "pip" That is how do I fix the symlink? I'm still beginnig to get symlinks :-) – dartdog Apr 26 '13 at 13:28
  • unutbu using what command? – dartdog Apr 26 '13 at 13:29
  • Actually I did try re installing pip with easy_install, no help.. – dartdog Apr 26 '13 at 13:36
  • Ahh I found the pip symlink in /usr/bin and is says it is broken as "This link cannot be used because its target "pip-2.7" does not exist" How to fix? – dartdog Apr 26 '13 at 13:43
  • What does `which pip-2.7` report back? – wkl Apr 26 '13 at 13:47
  • Which pip-2.7 /usr/local/bin/pip-2.7 but I do not see a pip-2.7 file in /usr/bin – dartdog Apr 26 '13 at 13:52
  • Looks like `pip-2.7` in `/usr/bin` was possibly removed by the install you ran (or something else uninstalled it). You can recreate a symlink in `/usr/local/bin` with `ln -s /usr/local/bin/pip-2.7 /usr/local/bin/pip` and then remove `pip` from `/usr/bin`. – wkl Apr 26 '13 at 14:18
  • did not work? sudo ln -s /usr/local/bin/pip-2.7 /usr/local/bin/pip ln: failed to create symbolic link `/usr/local/bin/pip': File exists tom@tom-sam:~$ – dartdog Apr 26 '13 at 14:45
  • In that case, I guess your `/usr/bin` takes precedence over `/usr/local/bin` in your `PATH`. You can do a `sudo rm /usr/bin/pip` to remove the broken symlink in there. After that, `pip` should work as the symlink in `/usr/local/bin` already exists. – wkl Apr 26 '13 at 14:54
  • damn, just what I though, I removed it and still getting bash: /usr/bin/pip: No such file or directory – dartdog Apr 26 '13 at 14:56
  • 3
    This did it sudo ln -s /usr/local/bin/pip-2.7 /usr/bin/pip – dartdog Apr 26 '13 at 15:09

6 Answers6

230

Before getting happy with apt-get removes and installs. It's worthwhle to reset your bash cache.

hash -r

Bash will cache the path to pip using the distrubtion install (apt-get) which is /usr/bin/pip. If you're still in the same shell session, due to the cache, after updating pip from pip your shell will still look in /usr/bin/ and not /usr/local/bin/

for example:

$apt-get install python-pip
$which pip
/usr/bin/pip

$pip install -U pip
$which pip
/usr/bin/pip

$hash -r
$which pip
/usr/local/bin/pip
boredcoding
  • 2,408
  • 2
  • 12
  • 5
  • I ran each command as stated above (for me: after executing _pip install -U pip_, console returned _/usr/local/bin/pip_) - everything worked, and I could run _pip freeze_ again! – Jacob Irwin Apr 02 '15 at 00:22
  • That was awesome :o) For the life of it I couldn't figure out why pip wasn't being executed when i could see /usr/local/bin in the PATH – Storm Jun 21 '16 at 06:32
  • Non distirbution software/libs/docs etc... are typically installed in /usr/local/xxx and not in /usr/xxx. if you echo $PATH you'll see /usr/local/bin listed before /usr/bin. This will ensure that things we installed outside of apt are considered first. This is a common issue with nodejs too as the exe is named nodejs and not node. Npm wants node. So we solve the problem by symlinking /usr/bin/nodejs to /usr/local/bin/node Hope this helps to understand why this works. – boredcoding Jun 21 '16 at 18:32
  • @etayluz Login as root user, type 'which pip' and verify it is /usr/local/bin/pip and not /usr/bin/pip. If it is /usr/bin/pip than the root path variable is not looking in /usr/local/bin/ before /usr/bin. 'hash -r' is just a cache reset it will do nothing for you if you path variable is actually wrong. When invoking sudo without telling bash to keep your logged in users environment active it will activate the root users environment. There are methods to retaining your environment when running sudo. for example. http://stackoverflow.com/questions/257616/sudo-changes-path-why – boredcoding May 03 '17 at 01:17
  • @etayluz To add to that, hash -r will only reset the cache for the logged in user. The solution could be as simple as just logging in as root and typing 'hash -r' or just adding /usr/local/bin; to the beginning of the root users path environment variable (or at least ensuring it's before /usr/bin). – boredcoding May 03 '17 at 01:21
  • This really helped me, after reinstalling and getting "No such file or directory" when running pip I used hash -r as you said and it solved the problem. Thanks! – ellpei Nov 12 '19 at 20:16
83

I had the same message on linux.

/usr/bin/pip: No such file or directory

but then checked which pip was being called.

$ which pip
/usr/local/bin/pip 

On my debian wheezy machine I fixed it doing following...

/usr/local/bin/pip uninstall pip  
apt-get remove python-pip  
apt-get install python-pip  

====================================
This was due to mixup installing with apt-get and updating with pip install -U pip.

These also installed libraries at 2 different places which caused problems for me.

/usr/lib/python2.7/dist-packages  
/usr/local/lib/python2.7/dist-packages
warvariuc
  • 57,116
  • 41
  • 173
  • 227
Martin Mohan
  • 1,366
  • 12
  • 8
  • 2
    This did it sudo ln -s /usr/local/bin/pip-2.7 /usr/bin/pip – dartdog Feb 09 '14 at 15:33
  • 9
    You really might want @boredcoding's answer over this one. – nedned Mar 14 '16 at 12:17
  • 4
    The answer is unfortunately incorrect *unless* you `hash -r` first. – gented Mar 29 '17 at 21:02
  • no need to uninstall or reinstall python-pip, if messed up env variables then put a symbolic link as suggested by @dartdog. As uninstall/reinstalling method will bring back the older version of pip 9.0 instead of 19.2. – Shaze Jul 23 '19 at 09:12
9

I had the same problem running Mint 18.1 after upgrading pip. I got it resolved simply by closing and opening the terminal.

Alex
  • 1,366
  • 19
  • 22
6

I had the same problem as @dartdog and thanks to @Martin Mohan and @warvariuc I was able to fully uninstall pip

Unfortunately using the command

apt-get install python-pip 

Was installing an old version of pip so after doing

/usr/local/bin/pip uninstall pip  
apt-get remove python-pip  

To install the latest pip version I got the get-pip.py file from https://bootstrap.pypa.io/get-pip.py

And once in the file directory from the command line executed the command python get-pip.py hope it helps someone

Also some of the commands need sudo good luck!!

サルバドル
  • 379
  • 1
  • 6
  • 12
  • You can update the system wide pip from pip with 'sudo pip install -U pip' sudo will, barring special cases, be required anytime you want to alter the system python, which includes using pip to install packages into the system wide packages folders. – boredcoding Jan 06 '18 at 17:58
  • For Python 2.7, use https://bootstrap.pypa.io/pip/2.7/get-pip.py instead – EliR Jul 07 '21 at 15:55
0

These two answers in other threads helped me out:

  1. Re-installing pip: https://stackoverflow.com/a/49997795/9377685

  2. pip started working after step 1, but kept showing an error:

RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown. warnings.warn(warning, RequestsDependencyWarning)

This answer helped in upgrading the cryptography and PyOpenSSL: https://stackoverflow.com/a/51284877/9377685

Jrct
  • 11
  • 4
-2

I was using pip with Python 3.5.2. Then I messed up during upgrade to Python 3.6 and I decided to revert to 3.5. After I removed pip-3.6, pip3 was pointing to /usr/local/bin/pip3, but the symlink to the actual pip install directory was missing. I fixed it with

sudo ln -s /usr/bin/pip3 /usr/local/bin/pip3