15

I've installed python using homebrew and I can't invoke pip from the bash. I've tried amending my .bash_profile to include /usr/local/bin/python and /usr local/share/python to no avail.

When I use the bash command:

find / -name 'pip'

The only results I get are:

/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip
/Users/Ivan/Library/Caches/pip
/Users/Ivan/Library/Logs/pip
/usr/local/Cellar/python/2.7.9/libexec/pip
/usr/local/Cellar/python/2.7.9/libexec/pip/pip
/usr/local/lib/python2.7/site-packages/pip

None of which are an executable.

I don't really know where to point my $PATH as I can't find the pip executable. When I open

/usr/local/lib/python2.7/site-packages/pip

or

/usr/local/Cellar/python/2.7.9/libexec/pip/pip

I find the following files:

__init__.py         commands            operations
__init__.pyc        compat              pep425tags.py
__main__.py         download.py         pep425tags.pyc
__main__.pyc        download.pyc        req
_vendor             exceptions.py       status_codes.py
basecommand.py      exceptions.pyc      status_codes.pyc
basecommand.pyc     index.py            utils
baseparser.py       index.pyc           vcs
baseparser.pyc      locations.py        wheel.py
cmdoptions.py       locations.pyc       wheel.pyc
cmdoptions.pyc      models

None of which are an executable.

I would appreciate the help of anyone with more experience than me.

Edit: I tried the steps suggested by Marco:

Here are the results to the steps:

  1. echo $PATH shows a few directories: /usr/local/bin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/opt/X11/bin:/usr/local/mysql/bin

  2. which -a python returns: /usr/local/bin/python /usr/local/bin/python

nothing is returned for which -a pip

  1. which python returns: /usr/local/bin/python

nothing is returned for which pip

  1. ls -l $(which python) returns a single directory: lrwxr-xr-x 1 Ivan admin 33 17 May 08:59 /usr/local/bin/python -> ../Cellar/python/2.7.9/bin/python

ls -l $(which pip) returns several, including the python files that I showed in my original post

4 Answers4

18

Generally, homebrew will install a formula into /usr/local/Cellar/formula and then place a link at /usr/local/bin/formula.

To make use of your installed formulae, make sure /usr/local/bin is in your $PATH. Show your $PATH by typing

echo $PATH

If /usr/local/bin is not in your $PATH, put this line at the end of your ~/.profile file.

export PATH="/usr/local/bin:$PATH"

Now, check what pythons are found on your OSX by typing:

which -a python

There should be one python found at /usr/bin/ (the Apple python) and one at /usr/local/bin/ which is the Homebrew python.

which python

will show you, which python is found first in your $PATH and will be executed when you invoke python.

If you want to know, where the executable is, show it by typing

ls -l $(which python)

This could look like this: lrwxr-xr-x 1 root wheel 68 7 Mai 13:22 python -> /usr/local/bin/python

This will work for pip as well.

If you show the results of this steps, we can probably help you much easier.

-- UPDATE --

You have /usr/local/bin/python linked to /usr/local/Cellar/python/2.7.9/bin/python. -> brew install python worked.

show, if pip is installed by typing

brew list python | grep pip

You should see

/usr/local/Cellar/python/2.7.9/bin/pip

If not, check, if there are links, which are not done with brew install. Told you something like this:

"Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local"

To force the link and overwrite all conflicting files:

brew link --overwrite python

To list all files that would be deleted:

brew link --overwrite --dry-run python

** NO standard Apple /usr/bin/python **

link from /usr/local/Cellar/python/2.7.9/bin/python to /usr/bin/python

ln -s /usr/local/Cellar/python/2.7.9/bin/python /usr/bin/python

This is necessary for all python scripts beginning with #!/usr/bin/python. Especialy easy_install will fail, if link is not there.

Now, you are able to run

easy_install pip

Hope, you're making progress

5

If brew is managing your python install and pip is no longer symlinked (i.e. you type "which pip" and get no results) try this from your home directory:

brew unlink python && brew link python

Not sure if the old method works any more (it didn't on my machine).

Now confirm it does indeed point to your 2.7 installation with pip --version (it will list the python major version in the directory output).

GrayedFox
  • 151
  • 1
  • 6
4

Not really an answer to the original question, but if anyone ends up here because their Homebrew-installed python/pip are no longer working (i.e. python points to the system python and pip is not found) then the reason might be a recent (summer 2017) change in the way Homebrew installs and links python.

The solution is to add the following to ~/.bash_profile and/or ~/.zshrc:

export PATH="$(brew --prefix)/opt/python/libexec/bin:$PATH"

This will make python point to the brew version of python and also give you pip. See the caveats section under brew info python and https://github.com/Homebrew/homebrew-core/issues/15746 for more information

bjorgvin
  • 151
2

By default Homebrew provides pip via: brew install python. However you will then have two Pythons installed on your Mac, you can alternatively install it via:

sudo easy_install pip

To verify which files are installed with your Python package, try:

$ brew list python
/usr/local/Cellar/python/2.7.9/bin/pip
/usr/local/Cellar/python/2.7.9/bin/pip2
/usr/local/Cellar/python/2.7.9/bin/pip2.7
...

which should consist pip.

After installation you should symlink your formula's installed files by:

brew link python

which should create the right symbolic links (such as /usr/local/bin/pip pointing to your Cellar/python/2.?.?/bin/pip)

If you've permission issue, you may fix it by:

sudo chgrp -R admin /usr/local /Library/Caches/Homebrew
sudo chmod -R g+w /usr/local /Library/Caches/Homebrew

and make sure your user is in admin group (id -Gn $USER).

After fixing the permissions, do not use sudo when using brew command.

Then re-link it again:

brew unlink python && brew link python

To test dry-run, unlink and run: brew link -n python to see links of files which brew would link.

After linking is successful, make sure that your PATH system variable have /usr/local, if not, add:

export PATH=/usr/local/sbin:/usr/local/bin:$PATH

to your ~/.bashrc file.

If successful, your pip should work now.

kenorb
  • 26,615