Install up-to-date scientific environment in Ubuntu 14.04 with Python 3.4

2014-05-14
#ubuntu #howto #python

Note: I’ve created an updated page with most recent instructions for Jupyter Notebook.

I use IPython notebook for processing numerical experiments results and plotting. The default Python 3 in Ubuntu 14.04 is 3.4, so it is easier to install really up-to-date bunch of software.

Full set of commands you need to install recent ipython notebook, numpy, scipy, etc in virtual environment almost without affecting shiny-new Ubuntu 14.04.

#!/usr/bin/env bash

sudo su
# install python development packages and g++
apt-get install -y python3-dev g++

# install dependencies for scipy
apt-get install -y libblas-dev liblapack-dev gfortran

# install dependencies for matplotlib
apt-get install -y libfreetype6-dev libpng-dev
exit

# ipython notebook has bug:
# https://bugs.launchpad.net/ubuntu/+source/python3.4/+bug/1290847

python3 -m venv --clear --without-pip venv/ipython-notebook

# activate virtual env and install pip
source venv/ipython-notebook/bin/activate

wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
rm get-pip.py

# install scientific packages
pip install numpy sympy matplotlib scipy pandas

# install ipython notebook and dependencies
pip install ipython pyzmq jinja2 pygments bokeh

# install latest dev scikit-learn and build it
pip install cython https://github.com/scikit-learn/scikit-learn/archive/master.zip

# install prettyplotlib by Olga Botvinnik for beauty plots
pip install brewer2mpl prettyplotlib

# deactivate venv
deactivate

Now create profile for ipython notebook and change there some settings. Activate virtual environment:

bikulov@kbux:~$ source venv/ipython-notebook/bin/activate

Generate password and exit ipython:

ipython
from IPython.lib import passwd; passwd()
exit()

Copy password hash to clipboard. Create profile with desired name:

ipython profile create [name]

Open ~/.ipython/profile_[name]/ipython_notebook_config.py and change settings:

c.NotebookApp.port = 8888
c.NotebookApp.ip = '0.0.0.0'
c.NotebookApp.open_browser = False
c.NotebookApp.password = [password hash]

Start ipython notebook server:

ipython notebook --profile=[name]

And open http://127.0.0.1:8888/ in your browser.