5

Lots of installation instructions tell you to do pip install [package]. But in my case that won't work, it'll say -bash: pip: command not found

python pip install [package] works OK. Likewise for easy_install, won't run by itself, will run when started with python.

I'm confused as to how it should work. Pip is no executable, there's no module called pip.py, there's only <path>\pip\__init__.py. So if pip install [package] is to work properly, the bash shell must understand when to act as a python interpreter. Which it doesn't.

I don't believe all those install instructions are off. So I must be missing something. What?

This didn't help, nor did this, in fact trying sudo apt-get install python-pip led to what I think is an unresolved bug. So I had to revert to this solution, to get me a somewhat working pip. (Now read again from the top).

Edit: Python 2.7. Not 3.x.

Community
  • 1
  • 1
RolfBly
  • 3,612
  • 5
  • 32
  • 46

4 Answers4

4

Most packages, including Debian's package, adds a /usr/bin/pip (or pip3, see below). See: https://packages.debian.org/jessie/all/python-pip/filelist

I think the pip installer via get-pip.py also does this.

The file basically relays it through python via console_scripts.

Check your /usr/bin and /usr/local/bin for pip. (if you installed pip outside of a package manager or without root/sudo then they probably don't exist). But they should...

If you're on python3, the file might be named pip3 so check /usr/bin and /usr/local/bin for that instead.

You can add an entry to your .bash_aliases to alias if you want the shortcut:

alias pip='pip3'
# or
# alias pip='python pip'
Hong
  • 172
  • 5
  • The alias is a nice workaround, thanks. There's a symlink `/usrbin/pip -> /usr/local/bin/pip` but the latter doesn't exist. – RolfBly Nov 23 '16 at 21:51
  • How did you install your current pip? Last place to look would be `$HOME/.local/bin/` but that would only be if you manually told python to install pip locally. If you have a symlink at `/usr/bin/pip` and the target doesn't exist, I think it should error when trying to run the pip command instead of saying command not found. `which pip` will there you where it's looking. – Hong Nov 23 '16 at 21:56
  • Which pip says nothing. Empty line. – RolfBly Nov 23 '16 at 22:08
  • Then it's not in your PATH, so you don't have a `/usr/bin/pip`. Was that a typo or is the directory actually named `/usrbin/pip` instead of `/usr/bin/pip` ? Could also check the output of `echo $PATH` to make sure /usr/bin is in it (but it definitely should be). – Hong Nov 23 '16 at 23:22
  • That's really strange... Anyway, my best guess is to check your `/root/.local/bin` if it exists or your main user's `$HOME/.local/bin`. The alias should work for you in the meantime, but having a questionable environment is never good for a developer. – Hong Nov 24 '16 at 19:15
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/128976/discussion-between-rolfbly-and-hong). – RolfBly Nov 24 '16 at 20:39
3

Attempts to re-install or fix failed. So I removed pip completely and did what I hope is a clean install. First:

sudo apt-get remove --auto-remove python-pip 

Then delete pips caches and existing downloads, where appropriate (in my case, I left still working pips inside virtual environments alone):

sudo find / -type d -name 'pip*'
sudo rm -rf <dirname>

Then download the official pip installer and install it:

wget https://bootstrap.pypa.io/get-pip.py 
sudo python get-pip.py  

Now pip freeze runs without errors. In addition:

  • the cause was that the pip-script was gone. After the re-install, it's there again: /usr/local/bin/pip. So what I thought:

    the bash shell must understand when to act as a python interpreter. Which it doesn't.

    is not right. The shell will launch a python script, if its shebang-line points to the proper interpreter. Learning all the time...

  • many sources suggest to sudo apt-get install python-pip. That's wrong. apt-get is several versions behind the current stable one. Mixing versions leads to all sorts of errors.

RolfBly
  • 3,612
  • 5
  • 32
  • 46
1

use python3 -m pip install X where X is the package name like if I want to install Pillow Python Imaging Library is will use

python3 -m pip install Pillow
Saif Siddiqui
  • 856
  • 1
  • 13
  • 33
1

This solved the issue for me.

Purge and reinstall pip.

sudo apt-get purge python-pip
sudo apt-get update
sudo apt-get install python-pip
Ebin Zacharias
  • 195
  • 1
  • 7