Creating Custom Jupyter Kernels in TLJH

This tutorial shows non-admin users how to create their own custom Jupyter kernels with specific Python packages. No admin access required!

Method 1: Create a Kernel from requirements.txt

Use this method when you have a requirements.txt file with the packages you need.

  1. Open a terminal in JupyterHub
    Go to: File → New → Terminal
  2. Create a virtual environment
    python3 -m venv ~/my-custom-env

    Replace my-custom-env with whatever name you prefer.

  3. Activate the environment
    source ~/my-custom-env/bin/activate
  4. Install ipykernel (required!)
    pip install ipykernel
  5. Install your packages
    pip install -r requirements.txt

    Or install packages individually:

    pip install pandas numpy matplotlib scikit-learn
  6. Register the kernel with Jupyter
    python -m ipykernel install --user --name=my-custom-env --display-name="My Custom Environment"

    The --display-name is what you'll see in Jupyter's kernel menu.

  7. Deactivate the environment
    deactivate

Method 2: Register an Existing Virtual Environment

If you already have a virtual environment set up, you can register it as a kernel.

  1. Activate your existing environment
    source /path/to/your/venv/bin/activate
  2. Install ipykernel if needed
    pip install ipykernel
  3. Register the kernel
    python -m ipykernel install --user --name=my-project --display-name="My Project"
  4. Deactivate
    deactivate

Using Your Custom Kernel

  1. Refresh your JupyterHub browser page
  2. Create a new notebook or open an existing one
  3. Go to: Kernel → Change Kernel
  4. Select your custom kernel from the list

Managing Your Kernels

List all available kernels:

jupyter kernelspec list

Remove a kernel you no longer need:

jupyter kernelspec remove my-custom-env

View kernel location:

Your kernels are stored in: ~/.local/share/jupyter/kernels/

Important Notes:

Example: Creating a Data Science Kernel

Here's a complete example for a data science environment:

# Create and activate environment
python3 -m venv ~/ds-env
source ~/ds-env/bin/activate

# Install packages
pip install ipykernel
pip install pandas numpy scipy matplotlib seaborn scikit-learn jupyter

# Register kernel
python -m ipykernel install --user --name=ds-env --display-name="Data Science"

# Deactivate
deactivate

Troubleshooting

Kernel doesn't appear in the list

Kernel fails to start