This is an archived version of the course. Please see the latest version of the course.

Lab Tutorial

Materials

Using JupyterHub

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. Note that these servers do NOT have GPUs enabled.

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

You can set up 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. If you are not familiar with virtual environments, see this tutorial on setting up virtual environments.

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

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

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

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

You can then run a notebook on JupyterLab with this 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.

(intro2ml) USER@machine:~$ pip install matplotlib