Skip to main content

Getting a sensible Python install on my Mac

I recently had to get Python + things I like up and running on my Mac from scratch. That’s a significantly harder task than you might guess, so one of the main reasons I’m posting this is for my own benefit (I’ll have to do this all again in February when I give my current laptop back to NIH and buy one of my own). There’s a decent chance this will be useful for others, though. A significant amount of experience and gnashing of teeth has told me

1) ActiveState is awesome, but not everything works perfectly with it.
2) Ditto for Python 2.7.
3) Never mix macports and fink.

So, here’s my setup for a working python2.6 system that happens to meet my current needs:

0) Fully uninstall macports (http://guide.macports.org/#installing.macports.uninstalling). Follow the full set of directions.

1) Install the latest and greatest macports, using the package install and the easy options (http://guide.macports.org/#installing.macports).

2) Make variants.conf reject all python2.7-related things
[lernerm@LCBB-ML01777274 ~]$ cat /opt/local/etc/macports/variants.conf
# To specify global variants to use for all port builds,
# customize this file to list variant settings you want.
#
# Any variants specified here that are not supported by
# a port will just be ignored. Multiple variants can be
# specified per line, or one per line is also allowed.
#
# Example:
# +ipv6 +no_x11
+py26 +python26 -py27 -python27 +bash_completion

3) Make sure you can install some basic things. I start with bash completion (https://trac.macports.org/wiki/howto/bash-completion) and coreutils.


sudo port install bash-completion
sudo port install coreutils +with_default_names

Note that you’ll have to edit your .bash_profile to make bash-completion work. It’s documented in the link above. You may also have to add /opt/local/libexec/gnubin to your path to get coreutils to work.

4) Install the Python environment I want, including
- python 2.6
- matplotlib
- numpy
- scipy
- ipython
- boost
- cgal
- cmake
- openbabel


sudo port install python26
sudo port select –set python python26
sudo port install py26-numpy py26-scipy py26-matplotlib py26-ipython py26-openbabel cmake boost cgal py26-wxpython py26-cython
sudo port select –set ipython ipython26

Change the noninteractive matplotlib default backend:


[lernerm@LCBB-ML01777274 ~]$ cat ~/.matplotlib/matplotlibrc
backend : WXAgg

5) Mercurial. I can’t use the macports package, because it forces a python2.7 install! The download from http://mercurial.selenic.com/downloads/ is fine, but I’d really rather have it as a port for consistency/upgrade reasons.

6) Then install additional packages I want

6a) numpy sharedmem (https://bitbucket.org/cleemesser/numpy-sharedmem/overview)


hg clone https://bitbucket.org/cleemesser/numpy-sharedmem
cd numpy-sharedmem
python setup.py build
python setup.py install –prefix=~/software # Note: that’s in my path already

6b) dionysus (http://www.mrzv.org/software/dionysus/get-build-install.html)


hg clone http://hg.mrzv.org/Dionysus/
cd Dionysus
hg up tip

mkdir build
cd build
cmake ..

add the following to CMakeLists.txt:


set(CMAKE_LIBRARY_PATH /opt/local/lib ${CMAKE_LIBRARY_PATH} )
set(CGAL_DIR /opt/local/lib/cmake)

That’s not enough. Edit CMakeCache.txt by hand to point at the right Python by searching for /System/Library/Frameworks/Python.framework and replacing it with /opt/local/Library/Frameworks/Python.framework and then, finally,


make

And then make sure that $HOME/src/Dionysus/build/bindings/python is in your PYTHONPATH.

6c) orange (from source http://orange.biolab.si/nightly_builds.html)


python setup.py build
python setup.py install –user

Note that the last bit requires you to have this in your .bashrc or .bash_profile (or both, or maybe they’re the same file because you’ve symlinked them!):


export PYTHONPATH=$HOME/.local/lib/python2.6/site-packages:$PYTHONPATH

Whew!

Comments from previous blog

  • From mglerner: I suppose numpy sharedmem could be done with python setup.py install --user. I tend to like --prefix=~/software, but that mysteriously didn't work for orange, so I'll probably switch everything over to --user for consistency.
  • From Anthony: But does Dionysus work? Finally?
  • From mglerner: Yes! Finally! I had this post 3/4 written for quite a while before I filled in the missing dionysus pieces.
  • From Anthony: So now that you're moving to python 2.7 you should update this. Do you have everything working yet?
  • From Ernest Yeung:
      Prof. Lerner, I was trying to get Dionysus to work, using Mercurial which went without a hitch, to work on my MacBook Air 13in, 2011, Mac OS X 10.8. Cmake and Boost were installed as required by mrzv.org (the author of Dionysus).
    
    I'm having problems at the build stage. By the way, what good directories should I put all this stuff in and should I be in administrator or a regular account to do all this?
    cd build % Yep, in Dionysus dir
    cmake ..
    
    That's when I get problems:
    CMake Error at /Applications/CMake 2.8-11.app/Contents/share/cmake-2.8/Modules/FindBoost.cmake:1106 (message):
    Unable to find the requested Boost libraries.
    
    Unable to find the Boost header files. Please set BOOST_ROOT to the root
    directory containing Boost or BOOST_INCLUDEDIR to the directory containing
    Boost's headers.
    Call Stack (most recent call first):
    CMakeLists.txt:13 (find_package)
    
    -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
    -- CGAL not found, therefore alphashapes will not be built.
    CMake Warning (dev) at examples/homology-zigzags/CMakeLists.txt:9 (add_executable):
    Policy CMP0002 is not set: Logical target names must be globally unique.
    Run "cmake --help-policy CMP0002" for policy details. Use the cmake_policy
    command to set the policy and suppress this warning.
    This warning is for project developers. Use -Wno-dev to suppress it.
    
    -- CGAL not found, alphashape bindings will not be built
    CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
    
    I installed boost onto the previous directory from my Dionysus. I installed it opening up the .tar.bz2 downloaded from the boost website. In your experience, does this work well?
    
    I'm not familiar the problems with CGAL. Do you have any knowledge?
    
    Maybe another way I should ask about all this is, if I only wanted a very minimal installation, all I want is Dionysus, with Mercurial, and of course what the author required CMake, Boost, how should I go about doing so?
    
    Many thanks, I'll write up what I learned on my blog and it may help others as well on a Mac.
    
    I share your passion for python.
    
    Facebook : ernestyalumni
    gmail : ernestyalumni
    linkedin : ernestyalumni
    tumblr : ernestyalumni
    twitter : ernestyalumni
    weibo 微博 : ernestyalumni
    youku : ernestyalumni
    youtube : ernestyalumni
    indiegogo : ernestyalumni
    

Comments

Comments powered by Disqus