Scientific Python Mode in the NMR Center

There are currently two scientific Python installations available at the Martinos Center. The more recent instillation is based on the Enthought Python Distribution (EPD). Users of the older "Legacy Scientific Python Installation" are encouraged to switch to the EPD based installation, as it is more actively supported and contains more up to date packages.

If you use Python, make sure to sign up for the martinos-python mailing list to receive updates regarding the Python installation and discuss Python related issues.

EPD Based Scientific Python Installation

Getting Started

On CentOS 5/6 (64-bit) do the following to enable the EPD based Python installation

setenv PATH /usr/pubsw/packages/python/epd/bin:${PATH}

or if you use Bash

export PATH=/usr/pubsw/packages/python/epd/bin:${PATH}

After this, you can run Python scripts by typing something like

 python my_script.py

To start an interactive Python (IPython) shell type

 ipython

For an integrated development environment specifically created for scientific Python type (in a bash/tcsh, not IPython)

 spyder &

this will start Spyder, which lets you edit, run, and debug Python scripts. For new Python users, the built in help is a also very useful.

spyder_screenshot_small.png

Resources for Learning Python

* Python Scientific Lecture Notes

* NumPy for Matlab Users

* The Boston Python User Group regularly holds meetings and organizes introductory Python classes

Available Python Modules

EPD comes with a large number of Python modules; an exhaustive list can be found here. In addition, the following neuroimaging related modules are installed:

* mne-python for M/EEG analysis

* nibabel provides access to a large number of neuro-imaging file formats

* nitime for time-series analysis

* pydicom enables you to read, modify and write DICOM files with python code

* PySurfer for visualization and interaction with cortical surface representations of neuroimaging data from FreeSurfer

If you know of other modules that should be made available to all users, send an e-mail to the martinos-python mailing list

EPD Versions and Installed Modules

The following table aims to give a complete list of all installed EPD versions and modules. The currently stable version is epd-7.0-2-rh5-x86_64. A different version can used by typing

setenv PATH /usr/pubsw/packages/python/${EPD_VERSION}/bin:${PATH}

where EPD_VERSION is one of the installed EPD versions.

Module

epd-7.0-2-rh5-x86_64

epd-7.1-1-rh5-x86_64

epd-7.2-2-rh5-x86_64

Bio

1.56

1.57

1.58

BioSQL

?

?

?

Crypto

2.3

2.3

2.4.1

Cython

0.14.1

0.14.1

0.15.1

IPython

0.10.1

0.11

0.12

OpenGL

3.0.1

3.0.1

3.0.1

OpenSSL

0.11

0.12

0.12

PIL

1.1.7-3

1.1.7-3

1.1.7-3

PySide

1.0.3

1.1.0

Pycluster

1.50-2

1.50-3

1.50-4

SCons

2.0.1

2.0.1

2.0.1

SimPy

2.1.0-2

2.1.0-2

2.2

appinst

2.0.4-1

2.1.0-1

2.1.0-1

apptools

4.0.0

4.0.1

bitarray

0.3.5

0.3.5

0.3.5

blockcanvas

4.0.0

4.0.1

bsdiff4

1.0.1

canica

0.0.0-py2.7

chaco

4.0.0

4.1.0

codetools

4.0.0

4.0.0

coverage

3.4

3.5

3.5.1

dap

?

?

?

dateutil

1.5

1.5

1.5

dicom

0.9.6

0.9.6

0.9.6

docutils

0.7

0.7

0.8.1

egginst

?

?

?

enable

4.0.0

4.1.0

enstaller

4.3.1

4.4.0

4.4.1

envisage

4.0.0

4.1.0

epydoc

3.0.1

3.0.1

3.0.1

etsdevtools

4.0.0

4.0.0

foolscap

0.6.1

0.6.1

0.6.2

fwrap

0.1.1-1

0.1.1-2

0.1.1-3

graphcanvas

4.0.0

4.0.0

h5py

1.3.1-1

1.3.1-2

2.0.0-1

hgext

?

html5lib

0.90

0.90

0.90

httplib2

$Rev: 259 $

$Rev: 259 $

$Rev: 259 $

jinja2

2.5.5

2.5.5

2.6

joblib

0.5.0a

0.6.3

0.6.3

kernmagic

?

?

kiva

?

?

lxml

2.3-1

2.3-1

2.3.2-1

mako

0.4.1

markupsafe

0.12

matplotlib

1.0.1

1.0.1

1.1.0

mayavi

4.0.0

4.1.0

mercurial

1.8.3-py2.7

mne

0.2.git

0.2

0.2

mpl_toolkits

?

?

?

netcdftime

0.9.3

networkx

1.4

1.5

1.6

nibabel

1.1.0

1.1.0

1.1.0

nipy

0.1.2.dev

nisext

?

1.1.0

nitime

0.4.dev

0.3.1

0.3.1

nose

1.0.1

1.0.0

1.1.2

numexpr

1.4.2

1.4.2

2.0

numpy

1.5.1

1.6.0

1.6.1

osgeo

1.8.1

pandas

0.2

0.3.0

0.6.1

paramiko

1.7.6 (Fanny)

1.7.7.1 (George)

1.7.7.1 (George)

pip

1.0.1

1.0.2

ply

3.3-3

3.4-1

3.4-1

pyamg

1.0.0.dev

1.0.0.dev

1.0.0.dev

pyface

4.0.0

4.1.0

pyfits

2.4.0

2.4.0

3.0.3

pyflakes

0.4.0

0.4.0

0.5.0

pygarrayimage

0.0.7-4

0.0.7-4

0.0.7-4

pyglet

?

?

?

pygments

1.4

1.4

1.4

pyhdf

0.8.3-4

0.8.3-5

0.8.3-6

pyproj

1.8.7

1.8.9

1.8.9

pytz

2010o

2011g

2011n

pyximport

?

?

?

reportlab

?

?

?

rope

0.9.3

0.9.3

0.9.3

scikits

0.9_git

0.10

?

scimath

4.0.0

4.0.1

scipy

0.9.0rc2

0.9.0

0.10.0

serial

?

?

?

setuptools

0.6

0.6

shapelib

?

?

?

skimage

0.4.2

sklearn

0.9

0.10

0.9

sphinx

1.0.7

1.0.7

1.1.2

spyderlib

2.1.4

2.1.4

2.1.8

spyderplugins

?

?

?

sqlalchemy

0.6.6

0.7.1

0.7.1

sqlalchemy_nose

?

surfer

0.2

0.1

0.2

sympy

0.6.7

0.7.0

0.7.1

tables

2.2.1

2.3b1.devpro

2.3.1

tornado

2.1.1-1

traits

4.0.0

4.1.0

traitsui

4.0.1

4.1.0

tvtk

?

?

twisted

10.2.0

11.0.0

11.1.0

virtualenv_support

?

vtk

5.6.0-2

5.6.0-2

5.6.0-2

wxPython

2.8.10.1

2.8.10.1

2.8.10.1

xlrd

0.7.1-3

0.7.1-4

0.7.1-4

xlwt

0.7.2-3

0.7.2-3

0.7.2-3

yaml

3.09

3.10

3.10

zmq

2.0.10-1

2.1.7

2.1.11

zope

?

?

?

Legacy Scientific Python Installation

Scientific Python mode is now available in the following platform/os combinations in the NMR center

The "system Python" ( the Python version which already exists in the system ) is not tampered with due to the following reasons:

  1. In CentOS systems, the Python version is very old ( 2.3.4 ) which prevents installation of many new modules essential for scientific computing in Python. However, a number of other system modules and programs are dependent on this version and it's best not to disturb this version.
  2. Leopard systems have a customized Python 2.5.x, which, again is a necessity for a number of modules. Again, best not to tamper with it.
  3. Isolation: The latest Python ( 2.6.3 ) and its associated modules are installed in /usr/pubsw/packages which are isolated from the system python and its modules. This configuration enables NMR center users to basically access both the versions of the Python and since both exist independently, they don't mess with each other.

Enabling the Scientific Python mode

By default, typing "python" to invoke the Python interpreter brings up the system Python interpreter which can be verified by looking at the version.

To enable the scientific python mode, users source the scientific python mode script in the following way :

source /usr/pubsw/packages/python/2.6/scientificpython/bin/tcsh_activate

Note: strongly recommended. this line can/should be put as an alias in one's ~/.cshrc in the following way:

alias pyactivate "source /usr/pubsw/packages/python/2.6/scientificpython/bin/tcsh_activate"

Once, this is done, the user can just type pyactivate to activate the scientific python mode and type deactivate to get back to the default ( normal system python mode )

In the scientific python mode, the prompt is preceded by the text (scientificpython), which lets the user know that he/she is in the scientific python mode. The user can invoke the python interpreter by typing python and notice that the interpreter is now the latest Python's interpreter. Once the user deactivates the mode, the prompt is changed back to the default prompt.

Note: The sourcing script works under tcsh shell. Bash is currently unsupported but will be if there are enough users using bash.

List of installed modules

Note : The list of modules indicated by (c) are compiled modules and the rest were installed using easy_install script.

Troubleshooting

  1. pylab doesn't start: This might be because there might be a stray .matplotlibrc file, which is already existing in your path preventing the standard backend to load. As an example, pylab can't be imported if the backend is WXAgg for Mac platforms or TkAgg for CentOS platforms. The fix is to comment out the line starting with backend in your .matplotlibrc ( usually in ~/matplotlib/matplotlibrc )

Behind the Scenes

( For advanced users )

A program called virtualenv is made use of to isolate the Pythons. virtualenv enables one to totally switch to a different Python with its own modules ( enabled by the switch --no-site-packages). So when the user sources the tcsh_activate script, what he/she is effectively doing is to prefix the system PATH, PYTHONPATH, module PATHs with the custom Python's paths and when the user deactivates he/she gets back all the default paths. virtualenv takes care of this complex paths manipulation behind the scenes. It also makes the modules installation a breeze for the administrator.