I currently need to work of some data on an ec2 cluster. Not wanting to do a lot of network I/O, decided to install the scientific python computing stack on an ec2 machine. Plus, I could utilize the IPython notebook to write my code, rather write code on a frustratingly slow shh terminal.

Outlining the steps I took to achieve this setup.

Note: Most of the steps are the same, one would take to install this stack on any *nix machine. Only the package managers would change.

Update system packages:

$ sudo apt-get update && sudo apt-get -y upgrade

Install packages needed for setting up all the requisite python packages

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

Install virtualenvwrapper

$ sudo pip install virtualenvwrapper
$ echo 'source /usr/local/bin/virtualenvwrapper.sh' >> ~/.bashrc
$ source ~/.bashrc

Make a virtual environment to install the packages

$ mkvirtualenv sample_env

I like to use bleeding edge ipython, get it from github

$ mkdir ~/Repo
$ git clone https://github.com/ipython/ipython.git
$ cd ipython/
$ git submodule update
$ pip install -e ".[notebook]"

Install the other python packages

$ pip install numpy scipy pandas matplotlib patsy statsmodels

To use pyQT backed plots, create a symlink to PyQt libraries when a new virtual environment is created. Source: github

$ wget wget https://gist.githubusercontent.com/jlesquembre/2042882/raw/160eb22a86f9c5a120033b9b05213b2aab8f79f6/postmkvirtualenv
$ chmod +x postmkvirtualenv
$ ./postmkvirtualenv

Add a line to matplotlibrc

$ mkdir ~/.matplotlib
$ echo backend: Qt4Agg >> ~/.matplotlib/matplotlibrc

Create a password to secure your ipython notebooks

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

Copy the sha1: and put it into the ipython config.

Now to configure ipython notebook to run on the server

$ ipython profile create myserver
$ vim ~/.ipython/profile_myserver/ipython_notebook_config.py

Edit the following parameters as per your requirements

c = get_config()
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 9999
c.NotebookApp.password = u'sha1:PasswordHash'
c.IPKernelApp.pylab = 'inline'

Run the IPython notebook

$ ipython notebook --profile=myserver

Navigate to the server ipaddress:port and login. Create a new IPython notebook and try

plot(arange(10))

If it works, you have a working setup.