Tuesday, January 11, 2011

Build Python on OS X with clang

I've been fooling around with clang as a gcc replacement. (I'd love to have Xcode 4 but it's not worth the $99). Here we build Python 2.7 in record time:


mkdir ~/temp
cd ~/temp
curl -O http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz
tar -zxf Python-2.7.1.tgz
mkdir Python
date


The date output:


Wed Jan 12 15:35:26 EST 2011



cd Python-2.7.1/
export CC=clang
./configure --prefix=/Users/telliott_admin/temp/Python --without-gcc
make && make install
date



Wed Jan 12 15:38:02 EST 2011


2 minutes and 36 seconds!


~/temp/Python/bin/python
Python 2.7.1 (r271:86832, Jan 12 2011, 15:36:42)
[GCC 4.2.1 Compatible Clang Compiler] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.version
'2.7.1 (r271:86832, Jan 12 2011, 15:36:42) \n[GCC 4.2.1 Compatible Clang Compiler]'
[1]+ Stopped ~/temp/Python/bin/python


The time stamp is interesting..


> file ~/temp/Python/bin/python
/Users/telliott_admin/temp/Python/bin/python: Mach-O 64-bit executable x86_64



cd ..
curl -O http://python-distribute.org/distribute_setup.py
~/temp/Python/bin/python distribute_setup.py
> cd Python/bin
> ls
2to3 pydoc python2.7-config
easy_install python smtpd.py
easy_install-2.7 python-config
idle python2.7

~/temp/Python/bin/easy_install-2.7 numpy
..
ImportError: No module named numpy.distutils


just hit it again and it'll finish


~/temp/Python/bin/python
Python 2.7.1 (r271:86832, Jan 12 2011, 15:36:42)
[GCC 4.2.1 Compatible Clang Compiler] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from numpy import *
>>>


However, I was unable to do a framework build to this location, and I was unable to build matplotlib either, at least so far.