Compiling Python 2.6 64-bit on Snow Leopard

Posted by Bryan in Web Development

python snow leopardI just finished upgrading to Python 2.6.5 on Mac OS X Snow Leopard. The default python build is 2.6.1. I wanted to compile the latest version. This would normally be a non-event, but the pain involved made it worth noting. The DMG file did not install the 64-bit binaries, so I needed to manually compile it.

Download the latest source tarball from python.org and extract it.

The Mac compile flags are a little deceiving. Since Snow Leopard is 64-bit, I needed to tell the build process to use the correct architecture. However, specifying "--with-universal-archs=64-bit" fails with the following error:

checking size of int... configure: error: cannot compute sizeof (int)

When using "--with-universal-archs=all", you'll get the following error:

checking size of wchar_t... configure: error: cannot compute sizeof (wchar_t)

Use this build command to avoid these errors:

./configure --enable-framework MACOSX_DEPLOYMENT_TARGET=10.6 --with-universal-archs=intel --enable-universalsdk=/Developer/SDKs/MacOSX10.6.sdk

After the compile process (configure, make and make install) completes, run the python shell:

import sys
print sys.maxint

If your int size is 2147483647, you are running the 32-bit binary. Open the python bin directory /Library/Frameworks/Python.framework/Versions/2.6/bin/. In it, you'll find 32-bit and 64-bit intel binary symbolic links. Relink the 32-bit with the 64-bit binaries.

sudo ln -sf python2.6-64 python
sudo ln -sf python2.6-64 python2.6
sudo ln -sf pythonw2.6-64 pythonw
sudo ln -sf python2.6-64 pythonw2.6

Open the python shell and output the sys.maxint value. If you are running 64-bit, it will be 9223372036854775807. Once confirmed, proceed with installation of the needed packages. The default PYTHONPATH will be /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/

Finally, I copied over my existing eggs and packages, then reinstalled setuptools, pysvn and MySQL 64-bit. The latest python is now good to go!

Comments

Thank you for posting this! I have been fighting the compiler trying to get 64-bit python on my Snow Leopard computer for weeks but never knew about those compiler flags. This worked perfectly.
Posted by Cody on Jun 02, 2010