Jupyter on Lawrence

Installing Jupyter

Request a node:

user.name@login ~]$ srun --pty bash
user.name@node02 ~]$

Make a directory for Jupyter scripts and cd into it.

user.name@node02 ~]$ mkdir jupyterScripts
user.name@node02 ~]$ cd jupyterScripts
user.name@node02 jupyterScripts]$

Copy the installation and starting scripts into your directory.

user.name@node02 jupyterScripts]$ cp /apps/jupyter-notebook/* ./
user.name@node02 jupyterScripts]$ ls
install-jupyter-notebook.sh  start-jupyter-notebook.sh
user.name@node02 jupyterScripts]$ 

Run the install script.

Note: If you would like to add kernels to your Jupyter Notebook (e.g. R, widgets, etc.), add the "-h" flag to view options:

  • user.name@node02 jupyter]$ bash install-jupyter-notebook.sh -h

user.name@node02 jupyterScripts]$ bash install-jupyter-notebook.sh
Creating new environment now...
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/usd.local/adison.kleinsasser/anaconda3/envs/jupyter

  added / updated specs:
    - ipykernel
    - jupyter


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    bleach-3.1.1               |             py_0         111 KB  conda-forge
    gst-plugins-base-1.14.5    |       h0935bb2_2         6.8 MB  conda-forge

Use "exit" to exit the node.

user.name@node02 jupyterScripts]$ exit
user.name@login jupyterScripts]$

Why do we request a node for the installation, and then exit out of it to start Jupyter?

Using another node for the installation process (install-jupyter-notebook.sh) keeps the login node open for users logging in, however, the script that starts Jupyter (start-jupyter-notebook.sh)requests a node (within the script), so being in the login node before running it is advised.

Starting Jupyter

(If you are entering the tutorial here, navigate to the directory that contains "start-jupyter-notebook.sh".)

Run start-jupyter-notebook.sh using bash.

Note: to see options for starting Jupyter, add an -h flag to the command:

  • user.name@login jupyter]$ bash start-jupyter-notebook.sh -h

user.name@login jupyter]$ bash start-jupyter-notebook.sh

If you have already opened Jupyter before (and your password is already set) you may skip to the "Start Tunnel" section.

Set a Password

If you are starting Jupyter for the first time, it will prompt you to create a password for your Jupyter Notebook installation. This can be changed or reset at a later time and is not related to your University password.

Note: the cursor will not move as you type- just like when typing the password to log into Lawrence.

Resetting your Password

If you forget your password and need to reset it:

Open your Jupyter environment.

user.name@usd.local@local jupyterScripts]$ conda activate jupyter
(jupyter) user.name@usd.local@local jupyterScripts]$

Then run "jupyter notebook password". Enter a new password when prompted. (Remember, the cursor won't move while typing a password.)

(jupyter) user.name@usd.local@local jupyterScripts]$ jupyter notebook password
Enter password:
Verify password:
[NotebookPasswordApp] Wrote hashed password to /home/usd.local/adison.kleinsasser/.jupyter/jupyter_notebook_config.json
(jupyter) user.name@usd.local@local jupyterScripts]$ 

Don't forget to deactivate your environment.

(jupyter) user.name@usd.local@local jupyterScripts]$ conda deactivate
user.name@usd.local@local jupyterScripts]$

Why do we bother having a password if it's so easy to reset?

Once the Jupyter server is started, anyone on Lawrence could theoretically access that Jupyter instance if they know the port it is using. The password protects your Jupyter from being accessible by unauthorized people who would have the same read/write access to any files your running Jupyter Notebook session can access.

Start Tunnel

After running the bash start-jupyter-notebook.shcommand (and setting a password if necessary), an ssh command and a localhost link will appear in the terminal (They aren't click-able).

Copy the ssh command from the print-out. (Do not use Ctrl-C, it'll cut off the job).

Open a second terminal, and paste the command into it.

Then hit "Enter".

Back in the first terminal, copy the localhost link:

Then open a browser, and paste it in the address bar (Note: your link will likely be different from the one shown- don't copy the one in the picture).

Press "Enter", then enter your password when prompted:

and Jupyter will come up.

Quit Jupyter

When you are done with Jupyter, don't simply close the browser. Make sure you shut down the server as well. Click on the "Quit" button in Jupyter:

The first terminal will then look like this:

Notice that the command prompt has come back. In the second terminal, use Ctrl-C to bring back the command line.

Last updated