fermi-lat / Fermitools-conda

Conda recipe files for the Fermi Sciencetools software analysis package: Fermitools
https://fermi.gsfc.nasa.gov/ssc/data/analysis/
BSD 3-Clause "New" or "Revised" License
34 stars 17 forks source link

Using fermitools in jupyterhub #133

Closed ldivenere closed 2 years ago

ldivenere commented 2 years ago

I had troubles using a fermitools environment in jupyterhub. The main issue was that the jupyter kernel linked to the conda environment was not correctly setting all the environment variables necessary to run the fermitools. I managed to solve the issue with this procedure:

  1. Activate conda environment in a jupyterhub shell: bash:~$ conda activate fermi

  2. Install kernel : bash:~$ python -m ipykernel install --user --name=fermi

  3. Create the kernel.sh file in the folder and make it executable: $HOME/.local/share/jupyter/kernels/fermi/kernel.sh

This is the content of the kernel.sh file:

#!/usr/bin/env bash
export CONDA_PREFIX=/path/to/conda/envs/fermi
source /path/to/conda/envs/fermi/etc/conda/activate.d/activate_fermitools.sh
exec /path/to/conda/envs/fermi/bin/python $@
  1. Modify the file $HOME/.local/share/jupyter/kernels/fermi/kernel.json Replace the first argv item "/path/to/conda/envs/fermi/bin/python" with this line: "$HOME/.local/share/jupyter/kernels/fermi/kernel.sh"

  2. Refresh jupyterhub and select fermitools kernel

ldivenere commented 2 years ago
  1. As an alternative, after step 1 you can run the script attached : bash:~$ ./setup_kernel_fermitools.sh <env_name> For example: bash:~$ ./setup_kernel_fermitools.sh fermi

setup_kernel_fermitools.txt