Install Jupyter Notebook and Scientific Environment in Ubuntu 14.04 With Python 3

2015-11-07
#ubuntu #howto #python #jupyter #ipython #numpy #scipy #seaborn

Several changes have occurred since my last note about installing the Python scientific environment:

Install prerequisites as root:

 1# install curl virtualenvwrapper
 2apt-get install -y curl virtualenvwrapper
 3
 4# install as workaround for https://github.com/matplotlib/matplotlib/issues/3029/
 5apt-get install -y pkg-config
 6
 7# install python development packages and g++
 8apt-get install -y python3-dev g++
 9
10# install dependencies for scipy
11apt-get install -y libblas-dev liblapack-dev gfortran
12
13# install some dependencies for matplotlib
14apt-get install -y libfreetype6-dev libpng-dev libjpeg8-dev

Now create and activate virtualenv, install all the packages via pip:

 1# create and activate virtual environment using mkvirtualenv wrapper (env name is jupnb)
 2mkvirtualenv --no-setuptools --python /usr/bin/python3.4 jupnb
 3
 4# install fresh pip
 5curl https://bootstrap.pypa.io/get-pip.py | python
 6
 7# install fresh setuptools
 8pip install setuptools distribute
 9
10# install numpy as it is dependecy for many others
11pip install numpy
12
13# install scientific packages (seaborn instead of matplotlib for pretty plots)
14pip install sympy scipy seaborn pandas jupyter
15
16# install scikit-learn separately, it depends on numpy and scipy
17pip install scikit-learn
18
19# deactivate venv
20deactivate

Configure the notebook profile with SSL encryption. Use a real SSL certificate instead of a self-generated one (if you have one). You can use the jupyter notebook --generate-config command to create a default config with comments about all the options, or use the following snippet for minimal config generation:

 1mkdir -p ~/.jupyter
 2cd ~/.jupyter
 3openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout ${ENV}.pem -out jupnb.pem
 4echo "c.NotebookApp.ip = '*'" >> jupyter_notebook_config.py
 5echo "c.NotebookApp.port = 8888" >> jupyter_notebook_config.py
 6echo "c.NotebookApp.open_browser = False" >> jupyter_notebook_config.py
 7echo "c.NotebookApp.password = u'$(ipython -c 'from notebook.auth import passwd; print(passwd())')'" >> jupyter_notebook_config.py
 8echo "c.NotebookApp.certfile = u'jupnb.pem'" >> jupyter_notebook_config.py
 9echo "c.NotebookApp.cookie_secret_file = '$HOME/.jupyter/secret_cookie'" >> jupyter_notebook_config.py
10cd -

That’s all. To use the notebook, activate the virtual env, run the server, and open http://127.0.0.1:8888/ in your browser:

1workon jupnb
2jupyter notebook