22

To preface, I am very bad with the terminal, please be patient with me.

when I run pip I get: zsh: command not found: pip

I have installed Python 2.7.11 with brew, which should allow pip to work When I run echo $PATH I get

/usr/local/sbin /Users/Nicolas/.composer/vendor/bin /Library/Frameworks/Python.framework/Versions/3.4/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin

I notice that /usr/local/bin/ is in there, which I understand is where brew executables are linked to

when I run which -a python I get

/usr/local/bin/python
/usr/bin/python

So-- two Python installs. I'm guessing one is the native OSX one and one is the homebrew install. When I run which python I get

/usr/local/bin/python

So this is the python that gets run when python is called, right? When I run ls -l $(which python) I get

lrwxr-xr-x  1 Nicolas  admin  34 Feb  3 14:26 /usr/local/bin/python -> ../Cellar/python/2.7.11/bin/python

I think this is where the problem is; I notice that there is a /python/2.7.11/libexec folder...

I have also tried brew unlink python && brew link python to no avail

when I try brew list python | grep pip I get a very long list of results

This is probably the most important one

/usr/local/Cellar/python/2.7.11/libexec/pip/pip/__init__.py

I don't know how to proceed from here... I think it has to do with pip being in python/2.7.11/libexec instead of python/2.7.11/bin

I am not familiar with most of this stuff; my understanding of terminal is very limited. I am not sure how to proceed from here. Any and all help is appreciated, thanks.

Nic Aguirre
  • 455
  • 1
  • 4
  • 19
  • 1
    Do yourself a favour, download get-pip.py https://bootstrap.pypa.io/get-pip.py and install it with python get-pip.py – Padraic Cunningham Feb 03 '16 at 20:14
  • I downloaded that to my desktop, cd'd there and ran python get-pip.py... I get this output: Requirement already up-to-date: pip in /Library/Python/2.7/site-packages/pip-8.0.2-py2.7.egg Collecting setuptools Downloading setuptools-19.7-py2.py3-none-any.whl (472kB) 100% |████████████████████████████████| 475kB 960kB/s Installing collected packages: setuptools Successfully installed setuptools-19.7 now when I run 'pip' I still get the same error (command not found) – Nic Aguirre Feb 03 '16 at 20:27
  • what does `which -a pip` output? – Padraic Cunningham Feb 03 '16 at 20:28
  • what about `/usr/bin/python -m pip` and `/usr/local/bin/python -m pip` – Padraic Cunningham Feb 03 '16 at 20:36
  • I don't understand -- are those commands? When I attempt to run the first one, I get Usage: /usr/bin/python -m pip [options] Followed by instructions... It doesn't appear to accept any parameters to the command. When I run /usr/bin/python -m pip -v It gives me the same output as with /usr/bin/python -m pip – Nic Aguirre Feb 03 '16 at 20:42
  • then it means pip is working, you could run `/usr/local/bin/python -m pip install requests` and it would work – Padraic Cunningham Feb 03 '16 at 20:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/102517/discussion-between-naguirre-and-padraic-cunningham). – Nic Aguirre Feb 03 '16 at 20:44

4 Answers4

25

I ran into this problem myself on OS X. In my case, I finally did a listing of /usr/local/bin, and found that I had links from pip2, pip2.7, pip3, and pip3.6. What I lacked was a link from just pip. I don't know if this is just part of a new standard, or if I was missing something that would select one of the two, or if having both Python 2 and Python 3 installed meant that I didn't get a simple pip command. Either way, running brew doctor didn't reveal or solve any issues.

In this case, just running pip3 or pip2 (instead of pip) seemed to do the trick for me. In my case, I ran pip3 and everything installed and ran as expected.

Steve Hollasch
  • 2,011
  • 1
  • 20
  • 18
  • 1
    quick fix based on this answer from @Steve - did `cd /usr/local/bin`, found the entry for `pip3`, noticed `pip` was missing, (inside that directory) simply copied the file to `pip` and everything worked! Thanks for the lead! `cp pip3 pip` – Kevin Foster Jan 28 '22 at 19:32
9

My Background

I had this same problem, and I think it may have arisen after upgrading to OSX 10.11 (El Capitan). When trying to run pip, I got -bash: pip: command not found I also tried python -m pip which did not work either (no module found). Trying to unlink and relink python through Homebrew did not work.

The Fix

I was able to fix the problem by completely uninstalling and reinstalling python via Homebrew.

brew uninstall python && brew install python

If you want to remove older versions of python too, use

brew uninstall --force python && brew install python

None of my existing pip installs were affected, and are all still listed when I run pip freeze. After the reinstall, the binary is now symlinked to /usr/local/bin/pip, which did not exist before. Strangely, the actual binary in /usr/local/Cellar/python/2.7.11/bin/pip did not exist before the reinstall either.

  • 1
    If brew complains about dependencies, you might have to do `brew uninstall --ignore-dependencies --force python && brew install python`. It's ok to ignore dependencies, because you're reinstalling right away. You might also have to relink: `brew unlink python && brew link python` – Christian Long Aug 17 '17 at 02:37
2

Uninstalling/reinstalling did not fix it for me but brew provided this info:

Unversioned symlinks python, python-config, pip etc. pointing to python3, python3-config, pip3 etc., respectively, have been installed into /opt/homebrew/opt/python@3.9/libexec/bin

So adding /opt/homebrew/opt/python@3.9/libexec/bin to my path fixed the issue.

Ian
  • 315
  • 1
  • 6
  • 13
0

For those who search for a solution also nowadays, with python 3 - brew installs them both, but and as you noticed, that's how you run python:

$ python3

That's the same story with pip:

$ pip3

If it bothers you (it bothers me) - you can alias those two to your prefered form:

$ alias python=python3
$ alias pip=pip3
Tzahi Leh
  • 2,002
  • 1
  • 15
  • 27