This is a set of instructions on how to set up a 3-way (i386, pcc, x86_64) Python development framework for Mac OS X.  This requires Xcode to be installed.


# Python.

Unpack Python 2.7, and then run:

$ ./configure --prefix=$HOME --enable-universalsdk=/Developer/SDKs/MacOSX10.5.sdk --with-universal-archs=3-way --enable-framework=$HOME/Library/Frameworks
$ make
$ make install

This will put the Python installation into ~/Library/Frameworks/Python.framework/Versions/2.7/ and the binaries will be symlinked in ~/bin.  Therefore add ~/bin to the system path by adding the following to .bash_profile:

PATH=$PATH:$HOME/bin
export PATH

Check the Python Framework 3-way architecture using the devel_scripts/framework_bin_test script.  The Tk module might fail as the 10.5 Mac SDK could be only i386 and ppc build.  Then a custom Tcl/Tk build will be required (e.g. at http://cran.r-project.org/bin/macosx/tools/) and the tkinter module build by hand, changing the -isysroot flag to / at the last step.



# Numpy.

Unpack numpy, and then run:

$ ~/bin/python2.7 setup.py install

This should take the deployment target platform, the architectures, etc. from the Python install.



# Scipy.

Install the appropriate GNU fortran version to add to Xcode (for example gfortran-42-5664.pkg from http://r.research.att.com/tools/).  Xcode does not come with a Fortran compiler and the fink version will not be able to create Universal 3-way binaries.

$ PATH=/usr/local/bin/:$PATH C_INCLUDE_PATH=/sw/include/suitesparse/ ~/bin/python2.7 setup.py install

The PATH option is needed if gfortran is located in both /usr/local/bin/ and /sw/bin/.  The C_INCLUDE_PATH may be needed if the suitesparse header files cannot be found.  If you still encounter swig problems finding the umfpack_*.h files, then manually type:

$ swig -I/sw/include/suitesparse/ -python -o build/src.macosx-10.5-fat3-2.7/scipy/sparse/linalg/dsolve/umfpack/_umfpack_wrap.c -outdir build/src.macosx-10.5-fat3-2.7/scipy/sparse/linalg/dsolve/umfpack scipy/sparse/linalg/dsolve/umfpack/umfpack.i
$ PATH=/usr/local/bin/:$PATH C_INCLUDE_PATH=/sw/include/suitesparse/ ~/bin/python2.7 setup.py install

The swig command will build the Scipy part requining the umfpack_*.h files, and then the python command will continue happily.



# Nose.

This is needed for numpy and scipy testing via the numpy.test() and scipy.test() functions.  Download the latest version from https://pypi.python.org/pypi/nose, unpack it and type:

$ ~/bin/python2.7 setup.py install

Do not use pip or easy_install!



# Mpi4py.

The deployment target platform, SDK root, and the architectures need to be set explicitly with environmental variables:

$ export MACOSX_DEPLOYMENT_TARGET='10.5'
$ export SDKROOT='/Developer/SDKs/MacOSX10.5.sdk'
$ export ARCHFLAGS='-arch i386 -arch x86_64 -arch ppc'

This is probably because mpicc is dumber than gcc!  Make sure that there is no 'build' directory prior to compilation.  Finally, run:

$ PATH=/usr/bin/:$PATH ~/bin/python2.7 setup.py install

The PATH change is required here just in case the non-framework Fink mpicc compiler is installed.



# wxPython 2.8.

Download and unpack the latest source release.  Create a build directory inside the unpacked sources and configure with:

$ mkdir bld
$ cd bld
#$ export arch_flags="-arch i386 -arch ppc -arch x86_64"
$ ../configure --prefix=$HOME \
             --with-mac \
             --with-opengl \
             --enable-debug \
             --enable-debug_gdb \
             --enable-geometry \
             --enable-graphics_ctx \
             --enable-sound --with-sdl \
             --enable-mediactrl \
             --enable-display \
             --enable-monolithic \
             --enable-unicode \
             --enable-universal_binary \
             --with-libjpeg=builtin \
             --with-libpng=builtin \
             --with-libtiff=builtin \
             --with-zlib=builtin \
             --with-macosx-sdk=/Developer/SDKs/MacOSX10.5.sdk \
             #--enable-framework=$HOME/Library/Frameworks \
             #CFLAGS='$arch_flags' \
             #CXXFLAGS='$arch_flags' \
             #CPPFLAGS='$arch_flags' \
             #LDFLAGS='$arch_flags' \
             #OBJCFLAGS='$arch_flags' \
             #OBJCXXFLAGS='$arch_flags'

Create an executable file in the 'bld' directory called '.make'.  Add the following text to the file:

make $* \
    && make -C contrib/src/gizmos $* \
    && make -C contrib/src/stc $*



# wxPython >= 2.9.

Download and unpack the latest source release.  In the base directory, type:

$ cd wxPython
$ ~/bin/python2.7 build-wxpython.py --build_dir=../bld --osx_cocoa --mac_universal_binary --prefix=$HOME --unicode --install



# SCons.

Download and unpack the latest release, then type:

$ ~/bin/python2.7 setup.py install
$ cd ~/bin
$ ln -s /Users/edward/Library/Frameworks/Python.framework/Versions/2.7/bin/scons scons

Then edit the scons file and change the top of the file from:

#! /usr/bin/env python
#
# SCons - a Software Constructor
#

To:

#! /Users/edward/bin/python
#
# SCons - a Software Constructor
#



# Py2app.

This is needed to create the universal binary DMG distribution file.  Download the latest version from https://pypi.python.org/pypi/py2app/.  Then open it and:

$ ~/bin/python2.7 setup.py install



# Matplotlib.

This might be used more in relax in the future.  Download the latest version and then:

$ ~/bin/python2.7 setup.py install
