Category: Mac



Update: 10/27/2011

I’m now on OS X Lion 10.7.2 and can confirm that the steps in this post will still get Python installed on your Mac.

Why Did I Replace the Default Python on Mac OS X?

Skip to the tutorial

Mainly, because tests were failing in my Django web application on my Mac that were passing on my Ubuntu setup. So I set out to create an up-to-date Python development environment on my Mac that works the same as the one on my Ubuntu box. Having successfully put Python 2.6.6 from python.org on my Mac, and fixed my web app, I’m sharing my results, setup, and solution with community.

Other Reasons to Replace the Python That Ships with Mac OS X

Python Interpreter Output: sys.maxint and sys.maxunicode

python -c "import sys; print sys.maxint;"
  • 9223372036854775807 (64-bit)
  • 2147483647 (32-bit)
python -c "import sys; print sys.maxunicode"
  • 1114111 (UCS-4)
  • 65535 (UCS-2)

Tutorial: How I Built Python 2.6.6 (64-bit) on Mac OS X

See also: Which Version of Python Do You Already Have Installed on Mac OS X? (Opens in a new Window)

  1. Install XCode from the Snow Leopard DVD
  2. Edit the first two lines of your .bash_profile to be:
    PATH="/usr/local/bin:/usr/local/sbin:/usr/local/bin/python:${PATH}"
    export PATH
  3. Download Python 2.6.6 source code:
    curl -O http://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz
    tar -xvf http://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz
    cd Python-2.6.6
  4. Edit /etc/paths and move the following line to the top of the file
    /usr/local/bin
  5. ./configure --disable-framework --disable-toolbox-glue \
    OPT="-fast -arch x86_64 -Wall -Wstrict-prototypes -fno-common -fPIC" \
    --enable-unicode=ucs4 LDFLAGS="-arch x86_64"
  6. make
  7. sudo make install
  8. cd into your home directory and type:
    source .bash_profile
  9. Open an interactive interpreter session, and if I’ve been successful in my instructions, you’ll see the following with different date/time information:
    Python 2.6.6 (r266:84292, Jan 30 2011, 21:45:16)
    [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.

Which Version of Python Do You Already Have Installed on Mac OS X?

Open the Terminal.app and type which python,  and on a fresh install of Snow Leopard you should see:

/usr/bin/python

This is a symlink that points to your actual Python installation.

Next, type cd /usr/bin; ls -l python2.6, and the output should be something like:

lrwx-xr-x 1 root wheel 75 Oct 7 23:24 python2.6 ->
../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/Python2.6

Now open an interactive interpreter session:

Python 2.61 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits", or "license" for more information.
>>>
Follow

Get every new post delivered to your Inbox.