Skip to content
Snippets Groups Projects
Commit 227ad4ab authored by Jens Henrik Goebbert's avatar Jens Henrik Goebbert
Browse files

remove output cells

parent 02d91212
Branches documentation
No related tags found
Loading
%% Cell type:markdown id: tags:
![banner.png](attachment:38ca1a72-2aa3-4660-8bdf-527e32e8187b.png)
<h5 style="text-align: right">Author: <a href="mailto:j.goebbert@fz-juelich.de?subject=Jupyter-JSC%20documentation">Jens Henrik Göbbert</a></h5>
<h5><a href="../index.ipynb">Index</a></h5>
<h1 style="text-align: center">Create your own Jupyter Kernel with pyenv</h1>
%% Cell type:markdown id: tags:
Often the standard kernel do not provide all features you need for your work. This might be that certain modules are not loaded or packages are not installed.
With your own kernel you can overcome that problem easily and define your own environment, in which you work.
This notebook shows you how you can build your own kernel for a **pyenv environment**.
<div class="alert alert-block alert-info">
<b>Attention:</b></br>
pyenv is a wonderful tool for managing multiple Python versions.</br>
You can easily try out new language features or help contribute to a project that is on a different version of Python.</br>
Using pyenv is also a great way to install pre-release versions of Python so that you can test them for bugs.</br>
</br>
<b>BUT</b>, if this is not your intention and you are fine with the default Python version of your current software stage.</br>
<b>DO NOT use pyenv</b> - please have a look at the general (PyPI) howto called "Create_JupyterKernel_general.ipynb" instead.</br>
</div>
<div class="alert alert-block alert-info">
<b>Attention:</b>
This notebook is meant to run out of a JupyterLab on JSC's HPC systems.</br>
</div>
--------------------------------------
%% Cell type:markdown id: tags:
## Building your own Jupyter kernel is a four step process
1. Install pyenv
* run the pyenv installation
1. Create/Pimp new virtual Python environment
* venv
2. Create/Edit launch script for the Jupyter kernel
* kernel.sh
3. Create/Edit Jupyter kernel configuration
* kernel.json
%% Cell type:markdown id: tags:
### Settings
%% Cell type:markdown id: tags:
#### Set the kernel name
- must be lower case
- change if you like
%% Cell type:code id: tags:
``` bash
# INPUT NEEDED:
KERNEL_NAME=${USER}_kernel_pyenv
export KERNEL_NAME=$(echo "${KERNEL_NAME}" | awk '{print tolower($0)}')
echo ${KERNEL_NAME} # double check
```
%% Output
goebbert1_kernel_pyenv
%% Cell type:markdown id: tags:
#### Set the kernel directory
- check that the kernel name is unique
- print the location of the new kernel
%% Cell type:code id: tags:
``` bash
# define KERNEL_SPECS_DIR
export KERNEL_SPECS_PREFIX=${HOME}/.local
if [ ! -d "$KERNEL_SPECS_PREFIX" ]; then
echo "ERROR: please create directory $KERNEL_SPECS_PREFIX"
fi
export KERNEL_SPECS_DIR=${KERNEL_SPECS_PREFIX}/share/jupyter/kernels
# check if kernel name is unique
if [ -d "${KERNEL_SPECS_DIR}/${KERNEL_NAME}" ]; then
echo "ERROR: Kernel already exists in ${KERNEL_SPECS_DIR}/${KERNEL_NAME}"
echo " Rename kernel name or remove directory."
fi
# print the location of the new kernel
echo ${KERNEL_SPECS_DIR}/${KERNEL_NAME}
```
%% Output
/p/home/jusers/goebbert1/jureca/.local/share/jupyter/kernels/goebbert1_kernel_pyenv
%% Cell type:markdown id: tags:
#### Set the kernel's pyenv environment
- by default it is located at $PROJECT
- print the location of the new kernels pyenv environment
%% Cell type:code id: tags:
``` bash
# define KERNEL_VENVS_DIR
export KERNEL_VENVS_DIR=${PROJECT}/${USER}/jupyter/kernels
mkdir -p ${KERNEL_VENVS_DIR}
# print the location of the new kernel's environment
echo ${KERNEL_VENVS_DIR}
```
%% Output
/p/project1/cjsc/goebbert1/jupyter/kernels
%% Cell type:markdown id: tags:
------------------------------
## 1. Install a new PyEnv
%% Cell type:markdown id: tags:
For a pyenv environment we do not use any prebuild modules of the system.
Instead we install everything from scratch with PyEnv - even Python itself.
%% Cell type:markdown id: tags:
#### 1.1 - Get all needed data for a pyenv installation
%% Cell type:markdown id: tags:
Just a simple command is needed to install pyenv in **$PYENV_ROOT**.
For simplicity we install a unique pyenv environment per kernel.
[(more)](https://github.com/pyenv/pyenv-installer?tab=readme-ov-file#install)
%% Cell type:code id: tags:
``` bash
export PYENV_ROOT=${KERNEL_VENVS_DIR}/${KERNEL_NAME}
if [ -d "${PYENV_ROOT}" ]; then
echo "ERROR: Directory for the pyenv installation already exists: ${PYENV_ROOT}"
echo " Rename kernel name or remove directory."
else
export PATH="$PYENV_ROOT/bin:$PATH"
curl https://pyenv.run | bash
echo ${PYENV_ROOT} # double check
fi
# print the location of the new pyenv environment
echo ${PYENV_ROOT}
```
%% Output
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 270 100 270 0 0 12028 0 --:--:-- --:--:-- --:--:-- 12272
Cloning into '/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv'...
remote: Enumerating objects: 1396, done.
remote: Counting objects: 100% (1396/1396), done.
remote: Compressing objects: 100% (725/725), done.
remote: Total 1396 (delta 856), reused 851 (delta 538), pack-reused 0 (from 0)
Receiving objects: 100% (1396/1396), 1.15 MiB | 28.08 MiB/s, done.
Resolving deltas: 100% (856/856), done.
Cloning into '/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv/plugins/pyenv-doctor'...
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 11 (delta 1), reused 5 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (11/11), 38.72 KiB | 19.36 MiB/s, done.
Resolving deltas: 100% (1/1), done.
Cloning into '/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv/plugins/pyenv-update'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 1), reused 5 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (10/10), done.
Resolving deltas: 100% (1/1), done.
Cloning into '/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv/plugins/pyenv-virtualenv'...
remote: Enumerating objects: 64, done.
remote: Counting objects: 100% (64/64), done.
remote: Compressing objects: 100% (57/57), done.
remote: Total 64 (delta 10), reused 23 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (64/64), 43.19 KiB | 21.59 MiB/s, done.
Resolving deltas: 100% (10/10), done.
/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv
/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv
%% Cell type:markdown id: tags:
#### 1.2 - Initialize the pyenv installation
%% Cell type:code id: tags:
``` bash
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
```
%% Cell type:markdown id: tags:
#### 1.3 - Install basic packages in the new pyenv installation
%% Cell type:markdown id: tags:
For these steps, make sure to have a clean & basic environment before starting this process.
%% Cell type:code id: tags:
``` bash
module purge
module load Stages/2025
```
%% Output
The following modules were not unloaded:
(Use "module --force purge" to unload all):
1) Stages/2025
%% Cell type:markdown id: tags:
- Install a python version (e.g. `3.12.3`)
%% Cell type:markdown id: tags:
<div class="alert alert-block alert-info">
<b>Attention:</b>
You are free to change the Python version here.</br>
</div>
%% Cell type:code id: tags:
``` bash
export PYTHON_VER=3.12.3
pyenv install ${PYTHON_VER}
```
%% Output
Downloading Python-3.12.3.tar.xz...
-> https://www.python.org/ftp/python/3.12.3/Python-3.12.3.tar.xz
Installing Python-3.12.3...
Installed Python-3.12.3 to /p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv/versions/3.12.3
%% Cell type:markdown id: tags:
- Double check the installation
%% Cell type:code id: tags:
``` bash
which python
which pip
python --version # should show system python version - not the version installed above because we have not activated a virtual environment, yet.
pip list
```
%% Output
/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv/shims/python
/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv/shims/pip
Python 3.9.21
Package Version
--------------- --------
chardet 4.0.0
ClusterShell 1.9.3
dbus-python 1.2.18
distro 1.5.0
gpg 1.15.1
idna 2.10
iotop 0.6
libcomps 0.1.18
nftables 0.1
pip 21.3.1
PyGObject 3.40.1
PySocks 1.7.1
python-dateutil 2.8.1
PyYAML 5.4.1
requests 2.25.1
rpm 4.16.1.3
selinux 3.6
sepolicy 3.6
setools 4.4.4
setuptools 53.0.0
six 1.15.0
systemd-python 234
urllib3 1.26.5
xenv 1.3
%% Cell type:markdown id: tags:
## 2. Create/Pimp new virtual Python environment
%% Cell type:markdown id: tags:
#### 2.1 - Create and activate a virtual environment for the kernel
%% Cell type:code id: tags:
``` bash
export PYENV_ENV=${KERNEL_NAME}
export VIRTUAL_ENV=${KERNEL_VENVS_DIR}/${KERNEL_NAME}/versions/${PYTHON_VER}/envs/${PYENV_ENV}
if [ -d "${VIRTUAL_ENV}" ]; then
echo "ERROR: Directory for virtual environment already ${VIRTUAL_ENV}"
echo " Rename kernel name or remove directory."
else
pyenv virtualenv ${PYTHON_VER} ${PYENV_ENV}
echo ${VIRTUAL_ENV} # double check
fi
```
%% Output
/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv/versions/3.12.3/envs/goebbert1_kernel_pyenv
%% Cell type:code id: tags:
``` bash
pyenv deactivate
pyenv activate ${PYENV_ENV}
```
%% Cell type:markdown id: tags:
#### 2.2 - Install whatever else you need in your Python virtual environment (using pip)
%% Cell type:markdown id: tags:
Jupyter requires the `ipykernel` module and its dependencies.
%% Cell type:code id: tags:
``` bash
which python
python --version # should show new installed python version (here 3.12.3)
```
%% Output
Python 3.12.3
%% Cell type:markdown id: tags:
<div class="alert alert-block alert-info">
<b>Attention:</b>
Now you can add extra Python packages you need.</br>
</div>
%% Cell type:code id: tags:
``` bash
if [ -z "${VIRTUAL_ENV}" ]; then
echo "ERROR: Virtual environment not successfully initialized."
else
echo "Installing custom Python packages using pip from the virtual environment:"
which pip
pip install ipykernel
# pip install <python-package you need>
fi
```
%% Output
Installing custom Python packages using pip from the virtual environment:
/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv/shims/pip
Collecting ipykernel
Using cached ipykernel-6.29.5-py3-none-any.whl.metadata (6.3 kB)
Collecting comm>=0.1.1 (from ipykernel)
Using cached comm-0.2.2-py3-none-any.whl.metadata (3.7 kB)
Collecting debugpy>=1.6.5 (from ipykernel)
Using cached debugpy-1.8.14-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (1.3 kB)
Collecting ipython>=7.23.1 (from ipykernel)
Using cached ipython-9.4.0-py3-none-any.whl.metadata (4.4 kB)
Collecting jupyter-client>=6.1.12 (from ipykernel)
Using cached jupyter_client-8.6.3-py3-none-any.whl.metadata (8.3 kB)
Collecting jupyter-core!=5.0.*,>=4.12 (from ipykernel)
Using cached jupyter_core-5.8.1-py3-none-any.whl.metadata (1.6 kB)
Collecting matplotlib-inline>=0.1 (from ipykernel)
Using cached matplotlib_inline-0.1.7-py3-none-any.whl.metadata (3.9 kB)
Collecting nest-asyncio (from ipykernel)
Using cached nest_asyncio-1.6.0-py3-none-any.whl.metadata (2.8 kB)
Collecting packaging (from ipykernel)
Using cached packaging-25.0-py3-none-any.whl.metadata (3.3 kB)
Collecting psutil (from ipykernel)
Using cached psutil-7.0.0-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (22 kB)
Collecting pyzmq>=24 (from ipykernel)
Using cached pyzmq-27.0.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.metadata (6.0 kB)
Collecting tornado>=6.1 (from ipykernel)
Using cached tornado-6.5.1-cp39-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (2.8 kB)
Collecting traitlets>=5.4.0 (from ipykernel)
Using cached traitlets-5.14.3-py3-none-any.whl.metadata (10 kB)
Collecting decorator (from ipython>=7.23.1->ipykernel)
Using cached decorator-5.2.1-py3-none-any.whl.metadata (3.9 kB)
Collecting ipython-pygments-lexers (from ipython>=7.23.1->ipykernel)
Using cached ipython_pygments_lexers-1.1.1-py3-none-any.whl.metadata (1.1 kB)
Collecting jedi>=0.16 (from ipython>=7.23.1->ipykernel)
Using cached jedi-0.19.2-py2.py3-none-any.whl.metadata (22 kB)
Collecting pexpect>4.3 (from ipython>=7.23.1->ipykernel)
Using cached pexpect-4.9.0-py2.py3-none-any.whl.metadata (2.5 kB)
Collecting prompt_toolkit<3.1.0,>=3.0.41 (from ipython>=7.23.1->ipykernel)
Using cached prompt_toolkit-3.0.51-py3-none-any.whl.metadata (6.4 kB)
Collecting pygments>=2.4.0 (from ipython>=7.23.1->ipykernel)
Using cached pygments-2.19.2-py3-none-any.whl.metadata (2.5 kB)
Collecting stack_data (from ipython>=7.23.1->ipykernel)
Using cached stack_data-0.6.3-py3-none-any.whl.metadata (18 kB)
Collecting python-dateutil>=2.8.2 (from jupyter-client>=6.1.12->ipykernel)
Using cached python_dateutil-2.9.0.post0-py2.py3-none-any.whl.metadata (8.4 kB)
Collecting platformdirs>=2.5 (from jupyter-core!=5.0.*,>=4.12->ipykernel)
Using cached platformdirs-4.3.8-py3-none-any.whl.metadata (12 kB)
Collecting parso<0.9.0,>=0.8.4 (from jedi>=0.16->ipython>=7.23.1->ipykernel)
Using cached parso-0.8.4-py2.py3-none-any.whl.metadata (7.7 kB)
Collecting ptyprocess>=0.5 (from pexpect>4.3->ipython>=7.23.1->ipykernel)
Using cached ptyprocess-0.7.0-py2.py3-none-any.whl.metadata (1.3 kB)
Collecting wcwidth (from prompt_toolkit<3.1.0,>=3.0.41->ipython>=7.23.1->ipykernel)
Using cached wcwidth-0.2.13-py2.py3-none-any.whl.metadata (14 kB)
Collecting six>=1.5 (from python-dateutil>=2.8.2->jupyter-client>=6.1.12->ipykernel)
Using cached six-1.17.0-py2.py3-none-any.whl.metadata (1.7 kB)
Collecting executing>=1.2.0 (from stack_data->ipython>=7.23.1->ipykernel)
Using cached executing-2.2.0-py2.py3-none-any.whl.metadata (8.9 kB)
Collecting asttokens>=2.1.0 (from stack_data->ipython>=7.23.1->ipykernel)
Using cached asttokens-3.0.0-py3-none-any.whl.metadata (4.7 kB)
Collecting pure-eval (from stack_data->ipython>=7.23.1->ipykernel)
Using cached pure_eval-0.2.3-py3-none-any.whl.metadata (6.3 kB)
Using cached ipykernel-6.29.5-py3-none-any.whl (117 kB)
Using cached comm-0.2.2-py3-none-any.whl (7.2 kB)
Using cached debugpy-1.8.14-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB)
Using cached ipython-9.4.0-py3-none-any.whl (611 kB)
Using cached jupyter_client-8.6.3-py3-none-any.whl (106 kB)
Using cached jupyter_core-5.8.1-py3-none-any.whl (28 kB)
Using cached matplotlib_inline-0.1.7-py3-none-any.whl (9.9 kB)
Using cached pyzmq-27.0.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (839 kB)
Using cached tornado-6.5.1-cp39-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (443 kB)
Using cached traitlets-5.14.3-py3-none-any.whl (85 kB)
Using cached nest_asyncio-1.6.0-py3-none-any.whl (5.2 kB)
Using cached packaging-25.0-py3-none-any.whl (66 kB)
Using cached psutil-7.0.0-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (277 kB)
Using cached jedi-0.19.2-py2.py3-none-any.whl (1.6 MB)
Using cached pexpect-4.9.0-py2.py3-none-any.whl (63 kB)
Using cached platformdirs-4.3.8-py3-none-any.whl (18 kB)
Using cached prompt_toolkit-3.0.51-py3-none-any.whl (387 kB)
Using cached pygments-2.19.2-py3-none-any.whl (1.2 MB)
Using cached python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB)
Using cached decorator-5.2.1-py3-none-any.whl (9.2 kB)
Using cached ipython_pygments_lexers-1.1.1-py3-none-any.whl (8.1 kB)
Using cached stack_data-0.6.3-py3-none-any.whl (24 kB)
Using cached asttokens-3.0.0-py3-none-any.whl (26 kB)
Using cached executing-2.2.0-py2.py3-none-any.whl (26 kB)
Using cached parso-0.8.4-py2.py3-none-any.whl (103 kB)
Using cached ptyprocess-0.7.0-py2.py3-none-any.whl (13 kB)
Using cached six-1.17.0-py2.py3-none-any.whl (11 kB)
Using cached pure_eval-0.2.3-py3-none-any.whl (11 kB)
Using cached wcwidth-0.2.13-py2.py3-none-any.whl (34 kB)
Installing collected packages: wcwidth, pure-eval, ptyprocess, traitlets, tornado, six, pyzmq, pygments, psutil, prompt_toolkit, platformdirs, pexpect, parso, packaging, nest-asyncio, executing, decorator, debugpy, asttokens, stack_data, python-dateutil, matplotlib-inline, jupyter-core, jedi, ipython-pygments-lexers, comm, jupyter-client, ipython, ipykernel
Successfully installed asttokens-3.0.0 comm-0.2.2 debugpy-1.8.14 decorator-5.2.1 executing-2.2.0 ipykernel-6.29.5 ipython-9.4.0 ipython-pygments-lexers-1.1.1 jedi-0.19.2 jupyter-client-8.6.3 jupyter-core-5.8.1 matplotlib-inline-0.1.7 nest-asyncio-1.6.0 packaging-25.0 parso-0.8.4 pexpect-4.9.0 platformdirs-4.3.8 prompt_toolkit-3.0.51 psutil-7.0.0 ptyprocess-0.7.0 pure-eval-0.2.3 pygments-2.19.2 python-dateutil-2.9.0.post0 pyzmq-27.0.0 six-1.17.0 stack_data-0.6.3 tornado-6.5.1 traitlets-5.14.3 wcwidth-0.2.13
[notice] A new release of pip is available: 24.0 -> 25.1.1
[notice] To update, run: python -m pip install --upgrade pip
%% Cell type:markdown id: tags:
## 3. Create/Edit launch script for the Jupyter kernel
%% Cell type:markdown id: tags:
#### 3.1 - Create launch script, which loads your Python virtual environment and starts the ipykernel process inside:
%% Cell type:code id: tags:
``` bash
# double check
echo ${PYENV_ENV}
echo ${PYENV_ROOT}
echo ${VIRTUAL_ENV}
```
%% Output
goebbert1_kernel_pyenv
/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv
/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv/versions/3.12.3/envs/goebbert1_kernel_pyenv
%% Cell type:code id: tags:
``` bash
echo '#!/bin/bash
module purge
module load Stages/2025
export PYENV_ROOT='"$PYENV_ROOT"'
export PATH='"$PYENV_ROOT"'/bin:'"$PATH"'
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
# Activate your Python virtual environment
pyenv activate '"${PYENV_ENV}"'
exec python -Xfrozen_modules=off -m ipykernel $@' > ${VIRTUAL_ENV}/kernel.sh
chmod +x ${VIRTUAL_ENV}/kernel.sh
echo ${VIRTUAL_ENV}/kernel.sh
cat ${VIRTUAL_ENV}/kernel.sh # double check
```
%% Output
/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv/versions/3.12.3/envs/goebbert1_kernel_pyenv/kernel.sh
#!/bin/bash
module purge
module load Stages/2025
export PYENV_ROOT=/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv
export PATH=/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv/bin:/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv/plugins/pyenv-virtualenv/shims:/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv/shims:/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv/bin:/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/jsc/bin:/usr/local/jsc/bin:/opt/parastation/bin:/p/software/default/bin
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
# Activate your Python virtual environment
pyenv activate goebbert1_kernel_pyenv
exec python -Xfrozen_modules=off -m ipykernel $@
%% Cell type:markdown id: tags:
---
## 4. Create/Edit Jupyter kernel configuration
%% Cell type:code id: tags:
``` bash
export VIRTUAL_ENV_KERNELS=${VIRTUAL_ENV}/share/jupyter/kernels
echo ${VIRTUAL_ENV_KERNELS}
```
%% Output
/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv/versions/3.12.3/envs/goebbert1_kernel_pyenv/share/jupyter/kernels
%% Cell type:markdown id: tags:
#### 4.1 - Create and adjust the kernel.json file
%% Cell type:code id: tags:
``` bash
mkdir -p ${VIRTUAL_ENV_KERNELS}/${KERNEL_NAME}
echo '{
"argv": [
"'${VIRTUAL_ENV}/kernel.sh'",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "'${KERNEL_NAME}'",
"language": "python",
"metadata": {
"debugger": true
}
}' > ${VIRTUAL_ENV_KERNELS}/${KERNEL_NAME}/kernel.json
echo ${VIRTUAL_ENV_KERNELS}/${KERNEL_NAME}/kernel.json
cat ${VIRTUAL_ENV_KERNELS}/${KERNEL_NAME}/kernel.json # double check
```
%% Output
/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv/versions/3.12.3/envs/goebbert1_kernel_pyenv/share/jupyter/kernels/goebbert1_kernel_pyenv/kernel.json
{
"argv": [
"/p/project1/cjsc/goebbert1/jupyter/kernels/goebbert1_kernel_pyenv/versions/3.12.3/envs/goebbert1_kernel_pyenv/kernel.sh",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "goebbert1_kernel_pyenv",
"language": "python",
"metadata": {
"debugger": true
}
}
%% Cell type:markdown id: tags:
#### 4.2 - Create link to kernel specs
%% Cell type:code id: tags:
``` bash
mkdir -p ${KERNEL_SPECS_DIR}
cd ${KERNEL_SPECS_DIR}
ln -s ${VIRTUAL_ENV_KERNELS}/${KERNEL_NAME} .
echo -e "\n\nThe new kernel '${KERNEL_NAME}' was added to your kernels in '${KERNEL_SPECS_DIR}/'\n"
ls ${KERNEL_SPECS_DIR} # double check
```
%% Output
The new kernel 'goebbert1_kernel_pyenv' was added to your kernels in '/p/home/jusers/goebbert1/jureca/.local/share/jupyter/kernels/'
conda_my_condaenv goebbert1_kernel_basemap julia-1.9
goebbert1_kernel2 goebbert1_kernel_htest pyenv_my_env
goebbert1_kernel3 goebbert1_kernel_pyenv
%% Cell type:markdown id: tags:
#### 4.3 - Use the kernel
- You can select the new kernel in the top right corner of your notebook or from JupyterLab's Launchpad
- The kernel icon will be added to your launcher, after a while by JupyterLab automatically or once you've restarted the JupyterLab
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment