Jonas T. Kaplan, Ph.D.

Table Of Contents

About This Guide
Before You Start
Step 1: Install Python 2.7
Step 2: Install Numpy
Step 3: Install Scipy
Step 4: Install NiBabel
Step 5: Install Matplotlib
Step 6: Install PyMVPA
Step 7: Install Ipython
After

About This Guide

update june 10, 2013:
We have found the Scipy Superpack to be very helpful. If you install this it will get you many of the required pieces, and you can then follow the instructions below to fill in the gaps for the parts remaining (i.e. nibabel, pymvpa).



This guide will help you to install PyMVPA on Mac OSX. The instructions for installation on the pymvpa website recommend using MacPorts to install pymvpa, however the MacPorts portfile is often out of date and may not install the latest version of available modules.

This guide is written in a "for dummies" style to be useful to a wider audience, so please don't be insulted if I am talking down to you. However, if you don't understand what I've written, you may resume feeling insulted. I do assume a basic familiarity with the OSX terminal. Commands to be typed into the terminal will appear in green font, and terminal output will appear in blue, like this:

echo hello
hello

Before You Start

Before you start it's important to have the OSX Developer Tools installed. This will give you the C compiler you will need to compile certain pieces. The installation of Developer tools has changed in 10.8. You now need to download XCode from the App Store, and then tell XCode to install the command line tools from its Preferences pane. (From the XCode Preferences, select Downloads and then Install "Command Line Tools".

We're going to be installing a fresh version of python, even though OSX comes with python. There's a couple reasons for this: 1) I have tested this installation process with python 2.7 so I know it works and 2) starting with a fresh install will make sure you haven't already installed other versions of the packages we are going to need. Note that this step is not strictly necessary. I'm not even sure which version of python OSX is shipping with nowadays so its possible you already have a nice fresh copy of 2.7. In other words, you can skip Step 1 if you want to. But even if you don't install a fresh python, its a good idea to hide your sw and opt folders as below.

In order to ensure that you don't have foreign stuff competing with python and with our compilations, its a good idea to start this process by hiding anything you have installed with Fink or MacPorts. Fink keeps all its installations in a folder at the root level of your hard drive called sw. MacPorts keeps all of its junk in opt. If we rename those folders, stuff in there won't be found by the system. For example, do:

sudo mv /sw /sw-moved
sudo mv /opt /opt-moved

When you're all done with the installation process described on this page you can move these folders back to their original names. If you dont have a /sw or /opt folder, that's fine, you're good to go. Let's just test and make sure we have the compiler from developer tools installed:

which make
/usr/bin/make

The which command asks the terminal to report the location of a given command; if it reports back a location we know that command is available and we know "which" one the terminal is going to use.

Step 1: Install Python 2.7

Download the Python 2.7.3 installer from the following link:

Python 2.7.3

Run the installer that you will find on the disk image to install Python 2.7.3. Once it is finished, let's check and make sure we have the right version installed:

python --version
Python 2.7.3

Great success!


Step 2: Install Numpy

Numpy allows python to do sophisticated number processing. Download and install this version:

Numpy 1.6.2

After you install, go back to the terminal and let's make sure python find the numpy package:

python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
import numpy
>>>

...so we get nothing. Nothing is good in this situation, it means python imported the numpy package successfully. If you try to import a package that isn't there, you get an error. For example:

>>> import snuffaluffagus
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named snuffaluffagus
>>>


To quit python and get back out to the bash shell, do

>>> exit()

Step 3: Install Scipy

Scipy contains a great set of tools for doing scientific computing with python. Install it with this:

Scipy 0.10.1

Once you've installed, let's just make sure python finds it:

python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
import scipy
>>>

Let's exit python again.

>>> exit()

Step 4: Install NiBabel

NiBabel is a module that allows you to read and write NIFTI, ANALYZE and MINC files. Download the source from here:

NiBabel Most Recent Version

I've provided you with a link to the most recent version, but just for reference I have done with with 1.3.0dev. OK, this one we are going to have to compile. The file you downloaded should have automatically decompressed and you should find a folder called something like "nipy-nibabel-aac6a66". The exact numbers at the end might change, don't worry about that. In your terminal, change directories into this folder, wherever it is for you. E.g:

cd /Users/jonask/Downloads/nipy-nibabel-aac6ac66

Now, compile the code with:

sudo python setup.py build

At this point you may be asked for your password. We are running all compile commands with sudo to make sure we have permission to write files wherever we may need to.

Missing optional package "dicom" provided by package "pydicom"; you may get run-time errors
running build
running build_py
running build_scripts


We can ignore the warning about dicom. Now that it has compiled without error, let's go ahead and install:

sudo python setup.py install

And to test it out:

python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
import nibabel
>>> nibabel.__version__
'1.3.0dev'
>>> exit()

( Those are two underscores before and after the word version. )

Step 5: Install Matplotlib

If you've gotten this far, you're doing pretty well. You've probably been cheering and high-fiving people around the lab. Don't get cocky. We're going to install matplot lib to which will handle all of our plotting needs. For some reason, this tends to be the most finicky part of the install.

First, download the source to matplotlib:

Matplotlib 1.1.1

Double-click the matplotlib-1.1.1.tar file to decompress it. You should now have the matplotlib-1.1.1 source code folder.

Download this modified make file to that folder. (We're going to build against the 10.7 SDK which is now located within the XCode app package. The modified makefile points there.)

And we are now ready to compile. From your terminal, change directory into the matplotlib source code folder and run the make command while crossing fingers:

cd /Users/jonask/Downloads/matplotlib-1.1.1
sudo PREFIX=/Library/Frameworks/Python.framework/Versions/2.7 make -f make.osx.modified.txt fetch deps mpl_install

You'll watch text fly by on your screen like the Matrix and when if it finishes without error you're in good shape. Let's test it:

python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
import numpy
>>> import pylab
>>> x = numpy.random.random(100)
>>> pylab.plot(x)
>>> pylab.show()
>>> exit()

If you got a chart to pop up that looks something like this, you can resume high-fiving the people around you.



You may need to close the chart to regain control of your python terminal.

Step 6: Install PyMVPA

It's time to finally install pymvpa itself. Download the source code from here. Adjust path below according to the name of the file your download. I have done this with version 2.1.0.

Double-click the tar archive to decompress it. In your terminal, change directory into the newly created pymvpa source code folder:

cd /Users/jonask/Downloads/PyMVPA-PyMVPA-1b31524

First we are going to build libsvm:

sudo make 3rd

Next we will build pymvpa itself:

sudo python setup.py build_ext

And assuming that completed without error*, install it:

sudo python setup.py install

Let's test it:

python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
from mvpa2.suite import *
>>>


*If the compilation process complains that you need to have SWIG installed, you may need to follow the steps here to install swig.
Step 7: Install Ipython

We're not quite done yet. While you could use pymvpa with your current setup, I highly recommend installing ipython, which is an improvement to the interactive python shell. To do this, download the source code:

Ipython 0.13

Change directory into the ipython source code folder you just downloaded, build ipython, and install it:

cd /Users/jonask/Downloads/ipython-0.13
sudo python setup.py build
sudo python setup.py install

Ipython really likes readline to be installed (it will work without it, but will complain), so let's install that too. Type:

sudo easy_install readline
Enter your password, and readline will be installed

Now we can use ipython instead of python from the terminal:

ipython
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
Type "copyright", "credits" or "license" for more information.

IPython 0.13 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.

In [1]:


One of the nice things about ipython is that it offers tab completion of python classes. For example:

In [1]: from mvpa2.suite import *
In [2]: mvpa2. (now hit tab a couple times...)
mvpa2.algorithms mvpa2.externals mvpa2.measures mvpa2.seed
mvpa2.atlases mvpa2.featsel mvpa2.misc mvpa2.suite
mvpa2.base mvpa2.generators mvpa2.np mvpa2.support
mvpa2.cfg mvpa2.hashfile mvpa2.os mvpa2.test
mvpa2.clfs mvpa2.hashfilename mvpa2.pymvpa_datadbroot mvpa2.tests
mvpa2.datasets mvpa2.kernels mvpa2.pymvpa_dataroot mvpa2.wtf
mvpa2.debug mvpa2.mappers mvpa2.random


Afterward

One thing you might want to do is download the tutorial data so that you can follow along with the pymvpa tutorial:

PyMVPA Tutorial Data

Put the folder some place you want it to stay, and then I recommend adding it to your python path so you can easily import the tutorial module. One way to do that is to add the following lines to your .bashrc file in your home directory:

export PYTHONPATH=${PYTHONPATH}:/Users/jonask/pymvpa/tutorial_data
export MVPA_LOCATION_TUTORIAL_DATA=/Users/jonask/pymvpa/tutorial_data

Of course, replace the path in that line with the path to wherever you put the tutorial data.

If you moved your /opt and /sw folders, now is the time to move them back.