Skip to content

Homebrew and Python

adamv edited this page Mar 29, 2011 · 28 revisions

Overview

Homebrew provides a formula for Python 2.7.1. This is somewhat counter to the "no system duplicates" policy, but Leopard comes with 2.5.x, Snow Leopard comes with 2.6.x, and it is useful to be able to get the latest Python 2 in an easy way.

Issues

Assuming a standard Homebrew install, the Prefix will be /usr/local and the Cellar will be /usr/local/Cellar.

Homebrew installs Python to the Cellar, using the standard ./configure --prefix=#{prefix}.

This sets up:

  • the "site-packages" folder as /usr/local/Cellar/python/2.7.1/lib/python2.7/site-packages.
  • the "install-scripts" folder as /usr/local/Cellar/python/2.7.1/bin.

If site-packages lives in Python's Cellar, then user installed packages will be wiped between Python updates. Same for install-scripts, with the added problem that users have to manually add Python's cellar bin folder to the path.

Solution

Homebrew performs two actions on install to address these issues.

First, the Cellar site-packages folder is removed, and a symlink to /usr/local/lib/python2.7/site-packages in the Prefix is created. This will allow site-packages to persist between Python updates, as Homebrew has special handling for some languages that use lib for user-installable libraries.

Second, a distutils.cfg file is written to set the install-scripts folder to /usr/local/share/python. Users can add /usr/local/share/python to the PATH to pick up installed scripts.

These changes allow Homebrew to play along with distutils (which is the basis for distribute and pip).

Standard python installers can be run as python setup.py install and the proper paths will be selected.

Distribute, Pip, etc.

The Python formula installs Distribute 0.6.15, which provides easy_install. pip can then be installed with:

easy_install pip

Distribute can be updated without re-brewing Python using pip:

pip install --upgrade distribute

The separate distribute and pip formulae have been removed.

Clone this wiki locally