Skip to content

Instantly share code, notes, and snippets.

@steindev
Last active September 4, 2025 11:44
Show Gist options
  • Select an option

  • Save steindev/39af88090f699ed0c1260dd4f0ab1d34 to your computer and use it in GitHub Desktop.

Select an option

Save steindev/39af88090f699ed0c1260dd4f0ab1d34 to your computer and use it in GitHub Desktop.
Install Jupyter kernel in custom conda environment on JUWELS
## Install a kernel for the picongpu analysis environment
##
## Before runnign this script, see JSC documentation at
## (https://jupyterjsc.pages.jsc.fz-juelich.de/docs/jupyterjsc/users/jupyterlab/4.3/kernels_hpc_conda/)
##
## The steps performed here are only the last ones after installing an own conda environment.
## For installing a suitable conda environment see
## (https://gist.github.com/steindev/c1d678375fd0f974f4b9cb1480b3da03)
##
CONDA_ENV=picongpu
export PROJECT=${PROJECT_jureap18}
export CONDA_ENV=$(echo "${CONDA_ENV}" | awk '{print tolower($0)}')
echo ${CONDA_ENV} # double check
export CONDA_TARGET_DIR=${PROJECT}/${USER}/miniforge3
echo ${CONDA_TARGET_DIR} # double check
echo '#!/bin/bash
module --force purge # optional to disable the external environment, necessary, if python version is different
# Activate your Python virtual environment
source '"${CONDA_TARGET_DIR}"'/bin/activate '"${CONDA_ENV}"'
# Ensure python packages installed in conda are always prefered, not necessary if module purge is used
export PYTHONPATH=${CONDA_PREFIX}/lib/python3.13/site-packages:${PYTHONPATH}
exec python -m ipykernel $@' > ${CONDA_TARGET_DIR}/envs/${CONDA_ENV}/kernel.sh
chmod +x ${CONDA_TARGET_DIR}/envs/${CONDA_ENV}/kernel.sh
echo ${CONDA_TARGET_DIR}/envs/${CONDA_ENV}/kernel.sh
mkdir -p $HOME/.local/share/jupyter/kernels/conda_${CONDA_ENV}
echo '{
"argv": [
"'"${CONDA_TARGET_DIR}"'/envs/'"${CONDA_ENV}"'/kernel.sh",
"-f",
"{connection_file}"
],
"display_name": "conda_'"${CONDA_ENV}"'",
"language": "python",
"metadata": {
"debugger": true
}
}' > $HOME/.local/share/jupyter/kernels/conda_${CONDA_ENV}/kernel.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment