Skip to content

Instantly share code, notes, and snippets.

@sono-bfio
Last active July 26, 2016 19:21
Show Gist options
  • Save sono-bfio/4a22723c7281fface6c9021f2eeb56fa to your computer and use it in GitHub Desktop.
Save sono-bfio/4a22723c7281fface6c9021f2eeb56fa to your computer and use it in GitHub Desktop.

Install Jupyter with Python 2 and Python 3 Kernels

  • Assumes you are logged in as the ubuntu user
  • Tested and run on ubuntu 14.04

Install Jupyter (Python2)

sudo pip2 install jupyter

List the kernels

jupyter kernelspec list
Available kernels:
  python2    /usr/local/lib/python2.7/dist-packages/ipykernel/resources

Install and register the kernel in user space as the ubuntu user

python2 -m ipykernel.kernelspec --user
Installed kernelspec python2 in /home/ubuntu/.local/share/jupyter/kernels/python2

Let's where the kernel is now acoording the ubuntu user

jupyter kernelspec list
Available kernels:
  python2    /home/ubuntu/.local/share/jupyter/kernels/python2

Generate a configuration file

jupyter notebook --generate-config -y
Writing default config to: /home/ubuntu/.jupyter/jupyter_notebook_config.py

Setup the configuration

Configuration file:

/home/ubuntu/.jupyter/jupyter_notebook_config.py

Append the contents below to the bottom of the config file:

 c = get_config()
 c.IPKernelApp.pylab = 'inline'
 c.NotebookApp.ip = '*'
 c.NotebookApp.open_browser = False
 c.NotebookApp.port = 8888

Install python 3 kernel

pip3 install ipykernel

Install the kernel spec locally

python3 -m ipykernel.kernelspec --user

kernel listing:

jupyter kernelspec list
Available kernels:
  python2    /home/ubuntu/.local/share/jupyter/kernels/python2
  python3    /home/ubuntu/.local/share/jupyter/kernels/python3

Create a directory for notebooks:

mkdir ~/pynb

Create a startup script:

Upstart Script:

/etc/init/jupyter.conf

Contents:

start on filesystem or runlevel [2345]
stop on shutdown

description "Jupyter / IPython Notebook Upstart script"

script
  export HOME="/home/ubuntu/pynb"; cd $HOME
  echo $$ > /var/run/ipython_start.pid
  exec su -s /bin/sh -c 'exec "$0" "$@"' ubuntu -- /usr/local/bin/jupyter notebook --config='/home/ubuntu/.jupyter/jupyter_notebook_config.py'
end script

Install Complete

At this point we have Jupyter (python 2 version) installed with Python 2 and Python 3 Kernels with Notebooks being installed in /home/ubuntu/pynb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment