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 occured since my last note about installing python scientific environment:

Install prerequisities as root:

# install curl virtualenvwrapper
apt-get install -y curl virtualenvwrapper

# install as workaround for https://github.com/matplotlib/matplotlib/issues/3029/
apt-get install -y pkg-config

# 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 some dependencies for matplotlib
apt-get install -y libfreetype6-dev libpng-dev libjpeg8-dev

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

# create and activate virtual environment using mkvirtualenv wrapper (env name is jupnb)
mkvirtualenv --no-setuptools --python /usr/bin/python3.4 jupnb

# install fresh pip
curl https://bootstrap.pypa.io/get-pip.py | python

# install fresh setuptools
pip install setuptools distribute

# install numpy as it is dependecy for many others
pip install numpy

# install scientific packages (seaborn instead of matplotlib for pretty plots)
pip install sympy scipy seaborn pandas jupyter

# install scikit-learn separately, it depends on numpy and scipy
pip install scikit-learn

# deactivate venv
deactivate

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

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

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

workon jupnb
jupyter notebook