IPython in-depth: Interactive Tools for Scientific Computing - Fernando Perez

Basic installation requirements

For the SciPy 2012 IPython tutorials, the most important thing you need to have installed is:

  1. a working version of IPython 0.13, released on June 30 2012, along with numpy and matplotlib.

  2. A modern web browser, i.e. Chrome (recent version), Firefox (version 7 or newer) or Safari (up to date). Please note that no version of Internet Explorer works for what we need, and the browser that works best in our experience so far is Chrome.

For Windows and Mac OS users, the easiest way to achieve this is to:

  1. Install EPD Free.
  2. Add IPython 0.13 on top of it. This can be achieved with the command

easy_install -U ipython

Linux users can also use EPD, though the current version of Ubuntu has enough of the dependencies we require that you can also use instead:

sudo apt-get install ipython ipython-notebook python-matplotlib

sudo easy_install -U ipython

once installed, ipython will give an error on startup until you comment out this line:

c.TerminalIPythonApp.extensions = ['kernmagic']

in the ipythonconfig.py file (~/.ipython/profiledefault/ipython_config.py on linux)

Sanity testing

In order to ensure that you have all the necessary tools running, please conduct the following tests:

  1. Basic IPython startup.

At a console prompt, type

ipython --pylab

and when IPython comes up, type

plot([1,2,3])

this should produce a plot window with a straight line. Then, type:

import IPython; print IPython.version

it should print '0.13'.

  1. IPython notebook startup

At a console prompt, type

ipython notebook

After a few seconds (up to a minute with a cold disk cache or a slower hard disk) a web browser should open up and show you a page with the 'IPython Dashboard'. If not, open Chrome or Firefox and point it to http://localhost:8888, which should show this page.

Click on the 'New Notebook' button, and you should see a page similar to this (without any content, of course): http://ipython.org/ipython-doc/rel-0.13/static/ipy013notebookspectrogram.png

In the first cell, type the following

%pylab inline

plot([1,2,3])

and hit Shift-Enter. The cell should evaluate and produce a plot with a straight line below it.

  1. IPython parallel startup from a console

At a console prompt, type

ipcluster start

This should produce some output indicating a cluster has been started, similar to:

2012-07-10 11:41:48,575.575 [IPClusterStart] Using existing profile dir: u'/home/fperez/.ipython/profiledefault' 2012-07-10 11:41:48.634 [IPClusterStart] Starting ipcluster with [daemon=False] 2012-07-10 11:41:48.635 [IPClusterStart] Creating pid file: /home/fperez/.ipython/profiledefault/pid/ipcluster.pid 2012-07-10 11:41:48.635 [IPClusterStart] Starting Controller with LocalControllerLauncher 2012-07-10 11:41:49.635 [IPClusterStart] Starting 4 Engines with LocalEngineSetLauncher

You can then stop this with Ctrl-C.

  1. IPython parallel startup from the notebook

Start the notebook (if you had shut it down after the test above) and on the Dashboard, click on the tab labeled 'Clusters'. Then, click on 'Start' for the first cluster profile listed. Then open a working notebook or create a new one, and execute a cell with the following:

from IPython.parallel import Client rc = Client() print 'Number of engines:', len(rc.ids)

It should print 2 or 4 (depending on the number of cores on your computer, more if you have a larger machine).

Optional add-ons

As part of the tutorial, we will briefly demonstrate a few additional capabilities of IPython, but we do not expect everyone to have these installed, so if you have trouble with them, you can watch our brief demo and you will not be behind.

  1. Qt: IPython provides a Qt console that requires that you install PyQt separately. You can find binary installers for pyqt at: http://www.riverbankcomputing.co.uk/software/pyqt/download/

  2. Cython, R: IPython can automatically call both Cython and R. If you'd like to use this on your system, then you will need to have installed Cython, a compiler, R and the rpy2 package. Since the installation of all this is beyond the scope of our tutorial, we only mention it for those who know how to go about it. Don't worry if you don't have these tools, we will show you briefly what can be done with them so you can decide later if it is worth learning how to install them on your system.

If you have any problems with the above, don't hesitate to contact your instructors directly:

"Fernando Perez" Fernando.Perez@berkeley.edu, "Min Ragan-Kelley" benjaminrk@gmail.com,

or feel free to post a question on the IPython user mailing list, to which you can subscribe here: http://mail.scipy.org/mailman/listinfo/ipython-user.