Skip to main content

Getting a working Python install, part 2

With the new laptop (side note: the 13″ MacBook Pro is a really nice machine. The screen certainly has enough pixels for real work, unlike previous 13″ machines. The only thing missing is a GPU.), it’s time to re-install. Since my last post, I’ve been convinced to upgrade to Python 2.7. Anthony Bak has recently gone through the same thing, so here’s my version of his set of notes on how to do this:

- ActiveState, the EPD, etc. are great, but don’t seem to play nicely with a few external packages.
- CMake causes lots of trouble, but there doesn’t seem to be a good alternative. I’m not sure why the macports version can’t be made to “just work”.

0) Fully uninstall macports ( Follow the full set of directions.

Then, go through your .bashrc/.bash_profile and collect all of the macports-related changes (they’ll all have /opt in them). Stick them at the end so that you can combine them with whatever macports does to your init files during the rest of the install.

1) Set /opt/local/etc/macports/variants.conf to contain

+python27 +py27 -python26 -py26 -universal +bash_completion

You’ll have to make the file and the directories, assuming you followed step 0.

2) Install the latest and greatest macports, using the package install and the easy options ( The rest of this guide was done with MacPorts-2.0.4-10.7-Lion.dmg.

3) Open a new shell so that your path is correct and run

sudo su # port requires superuser privs
port selfupdate
port upgrade outdated
port install coreutils python27
port select –set python python27
port install cmake boost mercurial cairo eigen py27-cython py27-numpy py27-scipy py27-wxpython-devel py27-matplotlib py27-pil

Note that we aren’t installing py27-wxpython because it requires
universal builds (which will mess up some other choices) so we use
py27-wxpython-devel instead.

4) Edit .bash_profile

export PATH=/opt/local/libexec/gnubin:/opt/local/bin:/opt/local/sbin:$PATH
export MANPATH=/opt/local/share/man:$MANPATH
export PYTHONPATH=$PYTHONPATH:/opt/local/lib/python2.7/site-packages:./

Also in there

export LDFLAGS=’-L/opt/local/lib’
export CPPFLAGS=’-I/opt/local/include’
export LD_LIBRARY_PATH=/opt/local/lib
export LD_INCLUDE_PATH=/opt/local/include

5) Now we handle cgal.

port extract cgal

Apply this patch:

The files are in


and the patch is tiny enough that it’s faster to just do it by hand.

Don’t install cgal. Instead

port build cgal
port install cgal


6) Download the openbable source distribution (latest is 2.3.1) . We’ll be installing by hand.

cd openbable-2.3.1
mkdir build
cd build

Edit CMakeCache.txt to fix all the python paths. Use

So, in emacs, a straightforward search and replace for /Library/Frameworks/Python.framework/ –> /opt/local/Library/Frameworks/Python.framework/ should work, but I had some trouble if I didn’t specify the specific version, so
/Library/Frameworks/Python.framework/ –> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/

make install

and even that never really worked for me. I also had to change a couple of instances of /usr/local/lib/python… to point to opt. And then the install failed. It installed all of the ob tools, but not the python .so. So, I copied it over by hand, and that seems to work.

So far, I am unable to get Mayavi installed from source. It works with the EPD, so I actually have two Python installations at the moment, sadly enough.

7) Install Dionysus( You have to tell it where the CGAL cmake files are.

cd Dionysus
mkdir build
cd build
cmake ../

Now edit the CMakeCache.txt file. Fix the python headers/path and
change the cgal dir (and maybe the same for boost).


cd bindings/python
mv lib_dionysus.dylib /opt/local/lib/
mv dionysus /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/
cd /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dionysus
ln -s /opt/local/lib/lib_dionysus.dylib

Install Fastcluster. Download from

sudo su python install

Install Mapper

Install sharedmem

hg clone
cd numpy-sharedmem
sudo python install

When you have time (on my machine graph-tool takes many hours and uses
>4GB durring the build phase):

port install py27-scikits-learn py27-scikits-statsmodels py27-networkx


Comments powered by Disqus