using pip with homebrew python

I eventually got around to updating all my Macs to 10.7 in what ended up being a few days before 10.8 was released. (I do realize the ridiculousness of the phrase “all my Macs”.) In changing over to the then-new version of OSX, I decided I wanted to be more intentional in setting up my Python environment, and specifically to use 2.7.3 for scripting and web dev, and to standardize this across machines. To do this, I use homebrew.

There is a page on the homebrew wiki that explains how brew handles installing Python and its package managers easy_install and pip. Following the instructions, including prefixing your PATH with /usr/local/bin and /usr/local/share/python, is supposed to leave you with both easy_install and pip installing packages for Python2.7, without the need to use sudo. It didn’t work for me. So, here’s the simple fix I had to make to get pip (and easy_install) working correctly:

If you type which pip at a bash prompt, and followed the instructions correctly, you’ll find it (and easy_install) in /usr/local/bin. If you open that file in your favorite text editor, though, you’ll find a shebang line at the top:

#! /usr/bin/python

that points pip to the system python. Edit that line to:

#! /usr/bin/env python

and pip will then correctly install packages for homebrew’s Python instead of system Python. I banged my head against the wall for a while trying to get pip to install packages correctly, until I thought to look at the pip file itself. Maybe now you won’t have to do that.

About

Associate Professor of Early Latin America Department of History University of Tennessee-Knoxville

Tagged with: , , , , ,
Posted in programming
2 comments on “using pip with homebrew python
  1. Matthew says:

    Thanks! This solved my problem (almost — actually I also had to run

    $ easy_install –upgrade pip

    as I was still getting an error “raise DistributionNotFound(req)
    pkg_resources.DistributionNotFound: pip==1.2.1”)

    anyway thanks!

  2. Hi there!
    What you have experienced can only be a bug and was not intended! Perhaps, I caused it, but it should be fixed already :-)

    So, right now the first line in the pip, that is installed by `brew install python` shows:
    `#!/homebrew/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python` for me.

    If you are willing to test this (again), I’d be happy if you put an Update to you post.
    It’s also easier for us to respond quickly, if you shout at us in our issue tracker ;-)

Leave a comment

parecer:
parecer:

Hacer juicio ú dictamen acerca de alguna cosa... significando que el objeto excita el juicio ú dictamen en la persona que le hace.

Deducir ante el Juez la accion ú derecho que se tiene, ó las excepciones que excluyen la accion contrária.

RAE 1737 Academia autoridades
Buy my book!



Chad Black

About:
I, your humble contributor, am Chad Black. You can also find me on the web here.