Skip to content

Instantly share code, notes, and snippets.

@steindev
Created July 3, 2023 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steindev/39af88090f699ed0c1260dd4f0ab1d34 to your computer and use it in GitHub Desktop.
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://docs.jupyter-jsc.fz-juelich.de/github/FZJ-JSC/jupyter-jsc-notebooks/blob/documentation/index.ipynb) -> 'Install kernel with conda'
##
## The steps performed here are only the lsat ones after installing an own conda environment.
##
CONDA_TARGET_DIR=/p/project/<PROJECTNAME>/<USERNAME>/miniconda3
CONDA_ENV=picongpu
echo '#!/bin/bash
# module 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.10/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
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"
}' > $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