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?
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
- Ability to develop in a cross-platform work environment
- Better Unicode support, UCS-4 instead of UCS-2 (see interpreter output below
- Bigger integers, more memory (see interpreter output below)
- Recommended by SciPy, I use SciPy
- Recommended by the community: http://www.python.org/download/mac/
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)
- Install XCode from the Snow Leopard DVD
- 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
- 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
- Edit /etc/paths and move the following line to the top of the file
/usr/local/bin
-
./configure --disable-framework --disable-toolbox-glue \ OPT="-fast -arch x86_64 -Wall -Wstrict-prototypes -fno-common -fPIC" \ --enable-unicode=ucs4 LDFLAGS="-arch x86_64"
-
make
-
sudo make install
- cd into your home directory and type:
source .bash_profile
- 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.
Thanks for the great article. I managed to install python however I’ve now got issues with installing packages with pip and my virtualenvwrapper is playing up. Is there any chance you can see what’s going on? Here’s my issue outlined: http://stackoverflow.com/questions/12321357/python-install-issue-on-mac-os-x
Michael: I’m sorry its taken a week to reply, and I’m glad you
were able to resolve your issue. I’ve had to uninstall all non-standard
packages from the system python myself before. I try my best to avoid
easy_install too. Python packaging (distribute, distutils, and setup_tools)
has been an area of much pain for many a programmer, but good news:
A comprehensive guide through Python packaging (a.k.a. setup scripts) by exhuma.twn at http://foobar.lu/wp/ has created one of the most comprehensive, super-awesome guides I’ve ever read. So good luck with Python and happy coding!
Yes they can be a bit of a pain as I’ve been learning! Thanks for the links, they look really useful!