pip not working on hombrew python 2.7 install
Solution 1
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
Solution 2
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).
Solution 3
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
Solution 4
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.
Related videos on Youtube
YoungPadawan
Updated on September 18, 2022Comments
-
YoungPadawan over 1 year
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:
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
which -a python returns: /usr/local/bin/python /usr/local/bin/python
nothing is returned for which -a pip
- which python returns: /usr/local/bin/python
nothing is returned for which pip
- 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
-
YoungPadawan almost 9 yearsMarco, thanks for your answer! Please see my original question for the results to the steps - I have added them in
-
YoungPadawan almost 9 yearsThanks for your answer kenorb! Part of the problem is that easy_install doesn't work for me either. In the bash I get: -bash: /usr/bin/easy_install: /usr/bin/python: bad interpreter: No such file or directory
-
kenorb almost 9 yearsThat means you don't have
/usr/bin/python
installed (which normally should be provided with OS X). So please try as suggested, which is:brew install python && brew link python
, then add/usr/local/bin
to yourPATH
. -
Marco M. von Hagen almost 9 years@YoungPadawan looks like you don't have Apple standard
/usr/bin/python
. This is not good, because many Python scripts start with#!/usr/bin/python
. If there is no python, you get error messages like yours. Usebrew link --dry-run python
to check, what will be changed to your links when usingbrew link --overwrite python
. We will get your pip running ;-) -
Marco M. von Hagen almost 9 yearsuse
brew link --overwrite --dry-run python
to see, which files will be overwritten. -
YoungPadawan almost 9 yearsI don't think that
brew install python && brew link python
is putting python in/usr/bin
. I'm seeing it inusr/local/bin
, but I'm not seeing the symlink to pip there. I've unlinked and linked python as well, and nothing changes. It seems that the brew install and link isn't putting things where it should -
kenorb almost 9 years@YoungPadawan
brew
doesn't do anything with/usr/bin
, but/usr/local/bin
. Try:brew unlink python
and dry-run:brew link -n python
to list all the files which should be linked and check ifpip
is there. If yes, run again without-n
. -
YoungPadawan almost 9 yearsI've ticked your answer because it led me down the right path, but in the end it was a permission issue. After installing I got a
Warning: The post-install step did not complete successfully You can try again using brew postinstall python. I tried the
brew postinstall python` command and it led me to a few files that I didn't have access to which I chowned. Now I can use pip! Thanks again -
YoungPadawan almost 9 yearsThanks Kenorb, I've found a solution. In the end it was a faulty install due to permissions. I modified the permissions on a few files that brew was conflicting with and re-ran the installation and now everything works fine. There are more details in a comment to the question above. Thanks again for your answer, it was really helpful in getting me to the solution.
-
David Pursehouse over 7 yearsIn my case the problem was
The post-install step did not complete successfully
due toerror: could not delete '/usr/local/lib/python2.7/site-packages/pip/__init__.py': Permission denied
. Manually deleting that file and then runningbrew postinstall python
again fixed it. -
Robeezy over 7 yearsnope, still doesn't work.
-
Robeezy over 7 yearsnope, none of this works, sorry bro.
-
kenorb over 7 years@Robeezy Ask a new question then, maybe your issue is somewhere else.