Jupyter Notebook Setup#

This section explains three typical workflows for using Jupyter in the PyClm101 environment:

  • Run Jupyter locally

  • Run Jupyter on a remote server (via SSH)

  • Convert a Jupyter notebook to a Python script


πŸ–₯️ Using Jupyter on Your Local Machine#

First, activate your environment:

conda activate geocat

Then start JupyterLab (recommended for local use):

jupyter lab

Or launch the classic Jupyter Notebook interface:

jupyter notebook

Your browser should open automatically. If not, visit the URL printed in the terminal (typically http://localhost:8888).


🌐 Using Jupyter on a Remote Server#

This is useful when working on a high-performance computing (HPC) cluster or university server.

πŸ’‘ Tip: On some remote servers, setting up Jupyter Notebook may be easier and more reliable than JupyterLab due to browser compatibility and firewall issues.

πŸ” Step 1: SSH into the remote server#

ssh your_username@your.server.address.edu

Replace your_username and your.server.address.edu with your actual credentials.

πŸš€ Step 2: Launch Jupyter on the remote server#

Activate your conda environment:

conda activate geocat

Option 2: Start JupyterLab (may not work on all remote setups)#

nohup jupyter lab --no-browser --port=8888 --ip=0.0.0.0 > jupyter_lab.log 2>&1 &

⚠️ Notes:#

  • Jupyter will automatically generate a token or password the first time you run it, which is required to connect.

  • If you see an β€œinvalid token” error, check the log file (jupyter_notebook.log or jupyter_lab.log) to find the correct URL and token.

  • If you see port conflict errors, try using an alternative port, e.g. --port=8899.

Example:

nohup jupyter notebook --no-browser --port=8899 --ip=0.0.0.0 > jupyter_notebook.log 2>&1 &

🧩 Step 3: Tunnel to the remote Jupyter server from your local machine#

Open a new terminal on your local machine and run:

ssh -L 8888:localhost:8888 your_username@your.server.address.edu

If using a different port (e.g., 8899), adjust the command:

ssh -L 8899:localhost:8899 your_username@your.server.address.edu

Then open your browser and visit:

http://localhost:8888

Or http://localhost:8899 if you changed the port.

πŸ”‘ Getting the token#

To find the token, check the output inside the log file:

cat jupyter_notebook.log

Look for a line like:

http://localhost:8888/?token=xxxxxxxxxxxxxxxx

πŸ” Converting Jupyter Notebooks to Python Scripts#

To convert a notebook (.ipynb) to a Python script:

jupyter nbconvert --to script my_notebook.ipynb

This will generate my_notebook.py in the same directory β€” useful for sharing, version control, or running as a batch script.


🚨 Troubleshooting#

πŸ”§ Check if the port is already used on the remote server#

Method 1: Using lsof#

lsof -i :8888

If no output is shown, the port is free. If you see an entry, another process is using it.

Method 3: Using netstat#

netstat -tuln | grep 8888

πŸ› οΈ Common Issues#

Issue

Possible Cause

Solution

Port already in use

Another service is using port

Use a different port (e.g. --port=8899)

Invalid token

Wrong token or expired session

Check jupyter_notebook.log for correct token

No browser opening

Use the URL shown in terminal

Copy and paste URL with token into your browser

Can’t connect via SSH

Wrong address or user

Double-check your SSH command and credentials