Setup a Remote IPython Notebook Server With Numpy/Scipy/Maltplotlib/Pandas in a Virtualenv on Ubuntu Server

by

I’m currently reading the book Python for data analysis and I have struggled to setup a remote IPython notebook server with all the scientific python stack, in a virtualenv, on Ubuntu Server. That’s why I share the steps I followed to get everything running, without the headhaches.

This guide will show you how to setup a remote IPython notebook server with the following features:

And we will install the following libraries: Numpy, Scipy, Pandas and Matplotlib.

I assume you have working virtualenvs.

Pylab

pylab is the combination of NumPy, Matplotlib, and IPython, so when you start IPython in pylab mode, all these module are already imported.

The only way to run IPython in pylab mode on a remote server is to run the IPython notebook server, you also need to install a backend to generate the chart, I choose to use python-qt4.

Installation

First we need to install some dependencies.

1
$ sudo apt-get install libatlas-dev libpng12-dev libfreetype6 libfreetype6-dev g++ libzmq-dev liblapack-dev gfortran python-dev build-essential python-qt4

Then, in your virtualenv:

1
$ pip install numpy scipy tornado pyzmq pandas ipython pygments matplotlib

Inline charts

We need to get pyqt4 installed in the virtualenv, since it doesn’t works with pip, I found a gist that do the job:

I found this gist to get pyqt4 working inside a virtualenv.

With the target virtualenv activated.

1
2
3
$ wget https://raw.github.com/gist/2042882/160eb22a86f9c5a120033b9b05213b2aab8f79f6/postmkvirtualenv
$ chmod +x postmkvirtualenv
$ ./postmkvirtualenv

And finally, you need to add that line in ~/.matplotlib/matplotlibrc.

1
$ vim .matplotlib/matplotlibrc
matplotlibrc - .matplotlib/matplotlibrc
1
backend: Qt4Agg

Configuring the notebook server

You should check out the IPython notebook docs.

First, get your password hashed with IPython utility.

1
2
3
4
In [1]: from IPython.lib import passwd
In [2]: passwd()
Enter password:
Verify password:

Next, create a new IPython configuration profile.

1
2
$ ipython profile create myserver
$ vim ~/.ipython/profile_myserver/ipython_notebook_config.py
IPython profile config file - ~/.ipython/profile_myserver/ipython_notebook_config.py
1
2
3
4
5
6
7
c = get_config()

c.IPKernelApp.pylab = 'inline'
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'sha1:yourhashedpassword'
c.NotebookApp.port = 9999

Running the server

Now, you can run the server, to keep it running, you can manage the process with Supervisor.

1
$ ipython notebook --profile=myserver

To check if inline chart works, just type that line in new notebook:

1
plot(arange(10))

That’s it, now you are able to access your notebook from everywhere.

 And you ?

Don’t hesitate if you have any questions or tips !

Comments