Jupyter Notebook Tutorial: Introduction, Setup, and Walkthrough

By Corey Schafer

In this Python Tutorial, we will be learning how to install, setup, and use Jupyter Notebooks. Jupyter Notebooks have become very popular in the last few years, and for good reason. They allow you to create and share documents that contain live code, equations, visualizations and markdown text.

Using Python 2 on JupyterHub

By default, JupyterHub uses Python 3.3. However you may want to use Python-2 on JuypterHub. You may want to take a look at Basic Setup and Configuration of JupyterHub with Python-3.4.3

Step 1: Install latest version of Python-2

You may want to see Installing and Compiling Python 2.7.8 on CentOS 5. You can apply this for CentOS 6

Step 2: Remember to install iPython2 and iPython[notebook] on Python-2

Do take a look at Installing scipy and other scientific packages using pip3 for Python 3.4.1 for some similar ideas

 Step 3: Install Python KernelSpec for Python 2

# /usr/local/python-2.7.10/bin/python2 -m IPython kernelspec install-self
# /usr/local/python-3.4.3/bin/python3 -m IPython kernelspec install-self

Step 4: Restart JupytHub

# juypterHub

Basic Setup and Configuration of JupyterHub with Python-3.4.3

This is a basic setup and configuration of JupyterHub from

Prerequisites:

  • JupyterHub requires IPython >= 3.0 (current master) and Python >= 3.3
  • Need to install nodejs/npm

Step 1: Install Python-3.4.3
You can use the tutorial to learn how to setup Python 3 (Compiling and Configuring Python 3.4.1 on CentOS)

Step 2: Install Nodejs and npm and Javascript Dependencies. You will need to install and enable EPEL repository

# yum install nodejs npm
# npm install -g configurable-http-proxy

Step 3a: Installation of JupyerHub

# pip3 install "ipython[notebook]"
# pip3 install jupyterhub
# git clone https://github.com/jupyter/jupyterhub.git
# cd jupyterHub
# pip3 install -r dev-requirements.txt -e .

Step 3b: Update Javascript

# python3 setup.py js
# python3 setup.py css

Step 4a: Update .bashrc or /etc/profile.d for python-3 path if you wish to affect global settings

# export PATH=/usr/local/python-3.4.3/bin:$PATH

Step 4b: Launch the JupyterHub Server

# jupyterhub

and then visit `http://localhost:8000`, and sign in with your unix credentials. If it does not work, no worry, just read on

Step 5: Generate a default config file:

# jupyterhub --generate-config

Step 6: Create Group shadow and put users into the group

The intention is to allow users to read the /etc/shadow file which is a requirements for jupytehub

# groupadd shadow
# chown root.shadow /etc/shadow
# usermod -G shadow user1
# chmod 040 /etc/shadow

If you are using DNS name instead of localhost, you would have to modify the jupyterhub_config.py found in /usr/local/juypterhub.
At approximately line 46, 181, modify localhost to your public-facing IP Address for the c.JupyterHub.hub_ip

c.JupyterHub.hub_ip = '10.10.10.10'

Step 6: Using sudo to run JupyterHub without root privilege

Do read the important document from JupyterHub wiki Using sudo to run JupyterHub without root privilege

Launch jupyterhub again.

# jupyterhub