Skip to content

Jupyter notebook

Usyally, the conda will install the jupyter notebook (and the ipykernel) by default.

If not, using conda to install it:

conda install jupyter

Using Jupyter notebook on a local or remote server

image

Using the default configuration

Local machine

You could open it in the Anaconda interface or some other IDE.

If using the terminal, just typing:

jupyter-lab --port 9000 &          

Then open the link in the browser.

http://localhost:9000/lab?token=???
http://127.0.0.1:9000/lab?token=???

Remote server

Start in the command line of the remote server, adding a port.

jupyter-lab --ip 0.0.0.0 --port 9000 --no-browser &
It will generate an address the same as above.

Then, on the local machine, using ssh to listen to the port.

ssh -NfL localhost:9000:localhost:9000 user@host
Note that the localhost:9000:localhost:9000 is localmachine:localport:remotemachine:remotehost and user@host is the user id and address of the remote server.

When this is finished, open the above in the browser.

Using customized configuration

Steps:

Create the configuration file

Create a jupyter notebook configuration file if there is no such file

jupyter notebook --generate-config

The file is usually stored at:

~/.jupyter/jupyter_notebook_config.py

What the first few lines of Configuration file look like:

head ~/.jupyter/jupyter_notebook_config.py
# Configuration file for jupyter-notebook.

#------------------------------------------------------------------------------
# Application(SingletonConfigurable) configuration
#------------------------------------------------------------------------------

## This is an application.

Add the port information

Simply add c.NotebookApp.port =8889 to the configuration file and then save. Note: you can change the port you want to use.

# Configuration file for jupyter-notebook.

c.NotebookApp.port = 8889

#------------------------------------------------------------------------------
# Application(SingletonConfigurable) configuration
#------------------------------------------------------------------------------

## This is an application.

Run jupyter notebook server on remote host

On host side, set up the jupyter notebook server:

jupyter notebook

Use ssh tunnel to connect to the remote server from your local machine

On your local machine, use ssh tunnel to connect to the jupyter notebook server:

ssh -N -f -L localhost:8889:localhost:8889 username@your_remote_host_name

Use jupyter notebook in your browser

Then you can access juptyer notebook on your local browser using the link generated by jupyter notebook server. http://127.0.0.1:8889/?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx