Brief Notes
Noteworthy links, summaries and concise prose on stuff.

Install the latest Python versions on Mac OS X Mountain Lion (10.8)

If your Mac never had Python installed via Homebrew (“The missing package manager for OS X”), you’ll see /usr/bin/python when you type the following command in an open Terminal window:

which python

/usr/bin/python is the location of the default Python executable that comes installed on your Mac.

To get the Python version:

python -V

Mine says 2.7.2 - this is older than the latest releases of Python. It’s advisable to install the latest versions of Python for development or to run the latest programs.

See Homebrew and Python for the reasons why it’s better to use Homebrew to install newer versions of Python than what originally came with your Mac. One important program that gets installed is pip, “a tool for installing and managing Python packages”. pip and pip3 are used to install Python packages and programs that will run under Python 2 and Python 3, respectively.

Following are the steps (adapted from the excellent How to Install Python 3 and PyDev on OSX, Installing Python on Mac OS X — The Hitchhiker’s Guide to Python and Python and Virtualenv on Mac OS X Mountain Lion 10.8 | Hacker Codex posts) for installing the latest versions of Python 2 and Python 3 on your Mac. If successful, you’ll see /usr/local/bin/python and /usr/local/bin/python3 when you run which python and which python3 respectively.

1. Ensure correct environment variables exist

Implement just the First steps portion of the instructions in Configuring Mac OS X Mountain Lion 10.8 on Hacker Codex, with one change, that is:

  • change this: export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
  • to this: export PATH=/usr/local/bin:$PATH.

2. Homebrew

In an open Terminal window, check if Homebrew is already installed on your Mac (mine is in /usr/local/bin/brew):

which brew

If Homebrew is installed, run an update if you haven’t already done so recently:

brew update

If Homebrew isn’t yet installed, install it:

ruby -e "$(curl -fsSL"

Always run Homebrew diagnostics before installing anything with it::

brew doctor

Follow any instructions emitted by the brew doctor command.

Install Python 2:

brew install python --framework

Install Python 3:

brew install python3 --framework

Check that Python versions 2 and 3 are correctly installed by entering the following:

which python
python -V
which python3
python3 -V

An example of the output I got from typing the above:

Python 2.7.5
Python 3.3.2

To upgrade a formula, say when a new version of Python 3 is released:

brew upgrade python3

To see a list of Homebrew formulae (python and python3 should be in the list):

brew list

To see installation details for, say, python3:

brew list python3

In my case, files for the python3 formula were installed in /usr/local/Cellar/python3/3.3.2/.

Files downloaded by Homebrew are located in /Library/Caches/Homebrew. You can periodically delete the files here after successful installations to reclaim some disk space.