7 Apr 2013 #python

Doing a minor version update for homebrew-installed Python

I install Python with homebrew (on OS X) and manage my packages with virtualenv. I was interested in whether updating from Python 2.7.3 to 2.7.4 would cause my virtualenvs to break. It did, but fixing them turned out to be very simple:

  1. First, of course, $ brew upgrade python; brew cleanup python, which installed Python 2.7.4 and then removed 2.7.3.

  2. According to this post, re-running virtualenv suffices to update the paths inside a virtualenv (the installed packages remain, and you shouldn’t need to re-install or recompile anything after a minor version update):

    $ virtualenv path/to/your-existing-virtualenv

  3. Finally, for globally-installed packages with executable scripts in /usr/local/share/python (including the homebrew-supplied pip), I also needed to change the first (hashbang) line in each file, replacing 2.7.3 in the path with 2.7.4:

    #!/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python

    to

    #!/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python

    This is easily done with the find and replace feature of your favorite text editor.

And voilĂ , everything works again.