Using Jupyterhub Kernels from the CLI
The available JupyterHub Python kernel environments can also be used directly from a terminal command line (CLI). This is useful for running Python scripts, command-line bioinformatics tools, batch jobs, or interactive Python sessions without opening JupyterHub.
The environments are installed under /opt/jupyterhub-kernels on all machines. Each JupyterHub Python kernel corresponds to a standard Python virtual environment in that directory. Use the same environment you would select as a kernel in JupyterHub for your needs.
- 1 Available environments
- 2 Method 1: Activate an environment
- 3 Method 2: Run the environment's Python directly
- 4 Using an environment in a script's shebang
- 5 Using the environments from shell scripts
- 6 Using environment variables and additional programs
- 7 Troubleshooting
- 8 Quick examples
- 9 Recommended practice
Available environments
JupyterHub kernel | Command-line environment |
|---|---|
Python 3.12 (Bioinformatics) |
|
Python 3.12 (ML/CPU) |
|
Python 3.12 (ML-JAX/CPU) |
|
Python 3.12 (ML/GPU NVIDIA) |
|
Python 3.12 (ML-JAX/NVIDIA) |
|
Python 3.12 (ML/GPU AMD ROCm) |
|
Python 3.12 (ML-JAX/ROCm) |
|
Since they are shared and centrally managed, virtual environments under /opt/jupyterhub-kernels are read-only: users cannot install, upgrade, or remove packages. This restriction ensures that environments continue to work consistently for all users.
Do not use sudo pip, and do not attempt to change permissions inside /opt/jupterhub-kernels.
If a package would be broadly useful, ask us (rctf-support@utexas.edu) to consider adding it to the appropriate shared environment. If you need packages only for your own project, create a personal virtual environment.
Method 1: Activate an environment
Activating an environment changes your shell so that commands such as python, pip, and installed command-line programs refer to that environment.
For general bioinformatics work:
source /opt/jupyterhub-kernels/python312-bio/bin/activateYour command prompt will normally change to show the active environment. You can then run Python:
pythonRun a script:
python analysis.pyOr use a command-line program installed in the environment:
ipythonTo verify which Python is active:
which python
python --versionThe result from which python should point inside /opt/jupyterhub-kernels, for example:
/opt/jupyterhub-kernels/python312-bio/bin/pythonWhen finished, leave the environment with:
deactivateActivation affects only the current terminal session. Opening another terminal will not automatically activate the environment.
Activation examples
Bioinformatics:
source /opt/jupyterhub-kernels/python312-bio/bin/activate
python analysis.pyCPU-based PyTorch or TensorFlow:
source /opt/jupyterhub-kernels/python312-ml-cpu/bin/activate
python train_model.pyCPU-based JAX:
source /opt/jupyterhub-kernels/python312-ml-jax-cpu/bin/activate
python jax_analysis.pyNVIDIA GPU with PyTorch:
source /opt/jupyterhub-kernels/python312-ml-gpu-nvidia/bin/activate
python train_model.pyNVIDIA GPU with JAX:
source /opt/jupyterhub-kernels/python312-ml-jax-nvidia/bin/activate
python jax_analysis.py
AMD GPU with PyTorch:
source /opt/jupyterhub-kernels/python312-ml-gpu-amd/bin/activate
python train_model.pyAMD GPU with JAX:
source /opt/jupyterhub-kernels/python312-ml-jax-rocm/bin/activate
python jax_analysis.pyMethod 2: Run the environment's Python directly
You do not have to activate an environment to use it. You can run its Python interpreter directly by using the complete path.
For example:
/opt/jupyterhub-kernels/python312-bio/bin/python analysis.pyFor a CPU-based machine-learning script:
/opt/jupyterhub-kernels/python312-ml-cpu/bin/python train_model.pyFor JAX on an NVIDIA GPU:
/opt/jupyterhub-kernels/python312-ml-jax-nvidia/bin/python jax_analysis.pyThis method is particularly useful in shell scripts, scheduled jobs, and batch-processing systems because it explicitly records which Python environment should be used.
For example:
#!/bin/bash
set -euo pipefail
PYTHON=/opt/jupyterhub-kernels/python312-bio/bin/python
"$PYTHON" "$HOME/projects/genomics/process_samples.py" \
--input "$HOME/data/samples.csv" \
--output "$HOME/results"Using the full path also avoids accidentally running the operating system's default Python or a different virtual environment.
Using an environment in a script's shebang
A script can specify a particular environment directly in its first line:
#!/opt/jupyterhub-kernels/python312-bio/bin/python
import pandas as pd
data = pd.read_csv("samples.csv")
print(data.describe())Make the script executable:
chmod +x summarize_samples.pyThen run it directly:
./summarize_samples.pyThis makes the script consistently use the selected shared environment, regardless of which Python is active in the user's shell.
A fixed shebang can be convenient, but it makes the script specific to machines where the environment exists at that exact path. For scripts that will be distributed to other systems, or run across multiple heterogeneous nodes, documenting the required environment and invoking it explicitly may be more portable.
Using the environments from shell scripts
For repeatable scripts, using an explicit interpreter path is usually better than relying on activation.
Recommended:
#!/bin/bash
set -euo pipefail
VENV=/opt/jupyterhub-kernels/python312-bio
"$VENV/bin/python" analysis.pyAlso valid:
#!/bin/bash
set -euo pipefail
source /opt/jupyterhub-kernels/python312-bio/bin/activate
python analysis.pyThe explicit-path version is generally easier to understand and less affected by shell startup files, aliases, or an already-active virtual environment.
Using environment variables and additional programs
Activating a virtual environment primarily changes PATH; it does not create a separate operating-system session. Your normal environment variables, home directory, files, and permissions remain unchanged.
For example:
source /opt/jupyterhub-kernels/python312-bio/bin/activate
export PROJECT_DIR="$HOME/projects/genomics"
python "$PROJECT_DIR/analyze.py"You can still run ordinary system commands:
grep
sort
vi
samtoolsWhether a non-Python command is available depends on what is installed on the host system or in the selected environment.
Troubleshooting
python still points to the wrong location
Deactivate any previously active environment and try again:
deactivate
source /opt/jupyterhub-kernels/python312-bio/bin/activateYou can always bypass activation by using the complete path:
/opt/jupyterhub-kernels/python312-bio/bin/python analysis.pyUsing import torch, import tensorflow, or import jax fails
These packages are not installed in every environment.
Use:
python312-ml-cpufor CPU PyTorch, TensorFlow, and Transformerspython312-ml-jax-cpufor CPU JAXpython312-ml-gpu-nvidiafor PyTorch and related software on NVIDIA GPUspython312-ml-jax-nvidiafor JAX on NVIDIA GPUspython312-ml-gpu-amdfor PyTorch and related software on AMD GPUspython312-ml-jax-rocmfor JAX on AMD GPUs
A GPU environment reports no GPU
Possible causes include:
The command is running on a CPU-only machine.
The environment does not match the GPU type.
The GPU is not visible to the current job or session (not in the render or video group).
The machine has an unsupported or partially supported GPU (e.g. AMD MI-50).
Required drivers or runtime services are unavailable.
pip install reports a permission error
The shared environment is read-only. Do not use sudo or attempt to change its permissions.
Request that a broadly useful package be added centrally, or create a personal environment for project-specific packages.
An environment is active, but a command is missing
The command may not be installed in that particular environment. Check:
command -v command-nameAnd inspect the environment's bin directory:
ls /opt/jupyterhub-kernels/python312-bio/binA Python module may also be runnable with python -m even if it does not provide a separate command:
python -m module_nameQuick examples
Start an interactive bioinformatics Python session:
source /opt/jupyterhub-kernels/python312-bio/bin/activate
pythonRun a pandas script without activating anything:
/opt/jupyterhub-kernels/python312-bio/bin/python summarize_data.pyRun a CPU PyTorch script:
/opt/jupyterhub-kernels/python312-ml-cpu/bin/python train.pyRun a JAX script on an NVIDIA GPU node:
/opt/jupyterhub-kernels/python312-ml-jax-nvidia/bin/python model.pyCheck which Python an activated shell is using:
python -c 'import sys; print(sys.executable)'Leave an activated environment:
deactivateRecommended practice
For interactive work, activate the environment:
source /opt/jupyterhub-kernels/python312-bio/bin/activateFor scripts, scheduled jobs, and reproducible command lines, use the full interpreter path:
/opt/jupyterhub-kernels/python312-bio/bin/python analysis.pyIn both cases, choose the same environment that you would choose as a JupyterHub kernel.