This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 4: Jupyter Notebook

JupyterHub

face Josiah Wang

The next level up in the Project Jupyter family is the JupyterHub. This is a server that runs Jupyter notebooks for multiple users.

CSG is testing a JupyterHub service that allows you to run Jupyter notebooks from your home directory on the departmental servers. You will need to access these servers through the College VPN. Also note that these servers do NOT have GPUs enabled.

Setting up your own kernel

The default Python 3 kernel provided does not have libraries like numpy and matplotlib installed.

You can set up your JupyterLab to use your custom own Python kernel that has these libraries installed.

Firstly, SSH to a departmental lab machine. And set up a Python virtual environment somewhere on your home directory.

Once you have a virtual environment set up on your home directory, activate the virtual environment. For example, if you have named your environment ml-coursework, then source ml-coursework/bin/activate.

USER@machine:~$ python3 -m venv ml-coursework
USER@machine:~$ source ml-coursework/bin/activate
(ml-coursework) USER@machine:~$ pip install numpy

Then you can create a new kernel with this virtual environment.

(ml-coursework) USER@machine:~$ pip install ipykernel
(ml-coursework) USER@machine:~$ python3 -m ipykernel install --user --name ml-coursework
Installed kernelspec in /homes/USER/.local/share/jupyter/kernels/ml-coursework
(ml-coursework) USER@machine:~$ jupyter kernelspec list
Available kernels:
  ml-coursework    /homes/USER/.local/share/jupyter/kernels/ml-coursework

You can then run a notebook on JupyterLab with this environment as your kernel. If you have multiple kernels installed, you can always switch kernels after you run your notebook via the menu “Kernel > Change Kernel”.

You can later install more packages to your virtual environment with pip install. Let’s say you need to install matplotlib, just install it to your virtual environment and you’re done! JupyterLab should automatically point to this virtual environment.

(ml-coursework) USER@machine:~$ pip install matplotlib