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 experiment results and plotting. The default Python 3 in Ubuntu 14.04 is 3.4, so it is easier to install a really up-to-date bunch of software.

The full set of commands you need to install a recent IPython Notebook, numpy, scipy, etc. in a virtual environment, almost without affecting your shiny-new Ubuntu 14.04.

 1#!/usr/bin/env bash
 2
 3sudo su
 4# install python development packages and g++
 5apt-get install -y python3-dev g++
 6
 7# install dependencies for scipy
 8apt-get install -y libblas-dev liblapack-dev gfortran
 9
10# install dependencies for matplotlib
11apt-get install -y libfreetype6-dev libpng-dev
12exit
13
14# ipython notebook has bug:
15# https://bugs.launchpad.net/ubuntu/+source/python3.4/+bug/1290847
16
17python3 -m venv --clear --without-pip venv/ipython-notebook
18
19# activate virtual env and install pip
20source venv/ipython-notebook/bin/activate
21
22wget https://bootstrap.pypa.io/get-pip.py
23python get-pip.py
24rm get-pip.py
25
26# install scientific packages
27pip install numpy sympy matplotlib scipy pandas
28
29# install ipython notebook and dependencies
30pip install ipython pyzmq jinja2 pygments bokeh
31
32# install latest dev scikit-learn and build it
33pip install cython https://github.com/scikit-learn/scikit-learn/archive/master.zip
34
35# install prettyplotlib by Olga Botvinnik for beauty plots
36pip install brewer2mpl prettyplotlib
37
38# deactivate venv
39deactivate

Now create a profile for IPython Notebook and change some settings there. Activate the virtual environment:

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

Generate a password and exit ipython:

1ipython
2from IPython.lib import passwd; passwd()
3exit()

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

1ipython profile create [name]

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

1c.NotebookApp.port = 8888
2c.NotebookApp.ip = '0.0.0.0'
3c.NotebookApp.open_browser = False
4c.NotebookApp.password = [password hash]

Start ipython notebook server:

1ipython notebook --profile=[name]

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