Nic Aguirre
Nic Aguirre

Reputation: 645

Running `pip` gives 'command not found' after successful Python homebrew install

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.

Upvotes: 30

Views: 38425

Answers (4)

Tzahi Leh
Tzahi Leh

Reputation: 2470

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

Upvotes: 3

Ian
Ian

Reputation: 345

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/[email protected]/libexec/bin

So adding /opt/homebrew/opt/[email protected]/libexec/bin to my path fixed the issue.

Upvotes: 5

Steve Hollasch
Steve Hollasch

Reputation: 2131

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.

Upvotes: 31

Damian Manda
Damian Manda

Reputation: 99

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.

Upvotes: 9

Related Questions