...
Install individual Python kernel
Jupyter allows you to work in your own virtual environment using the Python modules installed on the HPC. Start by loading the Python interpreter/module you want to work with, e.g.:
Codeblock |
---|
module load Python/3.11.3 |
Create a new virtual environment, e.g. in /gpfs/project/$USER, then update pip, setuptools and wheel (replace $USER with your username):
Codeblock |
---|
python -m venv --prompt py311 --system-site-packages /gpfs/project/$USER/py311
PIP_CONFIG_FILE=/software/python/pip.conf pip install --user --upgrade pip setuptools wheel |
Activate this environment and install all packages you want to work with - at least ipykernel must be installed
Codeblock |
---|
source /gpfs/project/$USER/py311/bin/activate
PIP_CONFIG_FILE=/software/python/pip.conf pip install ipykernel |
Create a new file "kernel.sh" in the main directory of your environment and make it executable
Codeblock |
---|
cd /gpfs/project/$USER/py311
vi kernel.sh
kernel.sh
----------------------------------------------------
#!/bin/bash
source /gpfs/project/$USER/py311/bin/activate
exec python -m ipykernel $@
----------------------------------------------------
chmod a+x kernel.sh |
Create a new directory for your kernel in your /home/.local/share folder
Codeblock |
---|
mkdir -p /home/$USER/.local/share/jupyter/kernels/py311
cd /home/$USER/.local/share/jupyter/kernels/py311 |
Create a new file "kernel.json" with contents
Codeblock |
---|
{
"argv": [
"/gpfs/project/$USER/py311/kernel.sh",
"-f",
"{connection_file}"
],
"display_name": "Venv (py311)",
"language": "python",
"metadata": {
"debugger": true
}
} |
In your next jupyterhub session a new kernel with the name "venv (py311)" will then be available.