Installing Jupyter Kernels

Last updated March 05, 2024

This user guide provides instructions for installing Jupyter kernels for use with the JupyterLab interactive app via CARC OnDemand. For more information about OnDemand and using Jupyter notebooks, see the CARC OnDemand user guides.

A Jupyter kernel is a programming language-specific process that executes the code contained in a Jupyter notebook. The following provides installation instructions for a few popular Jupyter kernels, which will be installed in your home directory at ~/.local/share/jupyter/kernels. Install the kernels when logged in to CARC systems before accessing them via the JupyterLab OnDemand interactive app. To learn more about installing software on CARC systems using the software module system, see the Software Module System user guide.

When installing kernels, make sure to use descriptive names in order to distinguish among them. Once installed, when launching Jupyter on OnDemand, the kernels will show up on a Launcher tab (File > New Launcher) and when selecting kernels through other methods.

Many software kernels are available for use with Jupyter. See a full list here: https://github.com/jupyter/jupyter/wiki/Jupyter-kernels.

0.0.1 Python

To install a Python kernel, install the ipykernel package and then create a kernel. For example, enter a set of commands like the following:

module purge
module load gcc/11.3.0 python/3.11.3
pip install ipykernel --user
python -m ipykernel install --user --name py3113 --display-name "Python 3.11.3"

Make sure to use a descriptive name.

The kernels will be able to access your user-installed Python packages.

To use Python packages that need certain libraries (via modules), add the modules to the “Additional modules to load” option (e.g., gcc/11.3.0 cuda/11.6.2) on the JupyterLab app form page. Alternatively, when JupyterLab is launched, navigate to the Lmod tab (labeled “Softwares”) on the left side, search for the modules via keyword, and then load them. After loading, start or restart the Python kernel.

0.0.2 R

To install an R kernel, first modify PATH to add the JupyterLab install path and load the R module version of your choice:

module purge
export PATH=/spack/conda/envs/ood-jupyterlab/bin:$PATH
module load gcc/11.3.0 openblas/0.3.20 r/4.3.2

Then within an R session, install the IRkernel package and create a kernel with a command like the following:

> install.packages("IRkernel")
> IRkernel::installspec(name = "r432", displayname = "R 4.3.2")

Make sure to use a descriptive name.

The kernel will be able to access your user-installed R packages.

To use R packages that need certain libraries (via modules), add the modules to the “Additional modules to load” option (e.g., gcc/11.3.0 gsl/2.7.1) on the JupyterLab app form page. Alternatively, when JupyterLab is launched, navigate to the Lmod tab (labeled “Softwares”) on the left side, search for the modules via keyword, and then load them. After loading, start or restart the R kernel.

0.0.3 Conda

First, set up your shell for Conda and create your environment—see the Using Conda user guide for instructions.

To use a Python kernel from a Conda environment, install the ipykernel package in the Conda environment and then create a kernel. For example, with a Conda environment named myenv, enter a set of commands like the following to create a Python kernel:

module purge
mamba activate myenv
mamba install -c conda-forge ipykernel
python -m ipykernel install --user --name myenv --display-name "My env"

Make sure to use a descriptive name.

To use an R kernel from a Conda environment, install the IRkernel package in the Conda environment and then create a kernel. For example, with a Conda environment named myenv, enter a set of commands like the following to create an R kernel:

module purge
mamba activate myenv
mamba install -c conda-forge r-irkernel
Rscript -e "IRkernel::installspec(name = 'r432', displayname = 'R 4.3.2')"

Use a descriptive name for your kernels.

0.0.4 Julia

To install a Julia kernel, first install the IJulia package:

pkg> add IJulia

Then install a kernel:

julia> using IJulia
julia> installkernel("Julia")

The kernel will be able to access your user-installed Julia packages.

0.0.5 Stata

To install a Stata kernel, enter the following commands:

module purge
module load gcc/8.3.0 python/3.9.2 stata/16
pip install stata_kernel --user
python -m stata_kernel.install --user

On the JupyterLab app form page, add gcc/8.3.0 stata/16 to the “Modules to load” option. Alternatively, when JupyterLab is launched, navigate to the Lmod tab (labeled “Softwares”) on the left side, search for the modules via keyword, and then load the needed modules. Then start or restart the Stata kernel.

0.0.6 MATLAB

To install a MATLAB kernel, enter the following commands:

module purge
module load gcc/8.3.0 python/3.7.6 matlab/2020b
pip install imatlab --user
python -m imatlab install --user

The matlab/2020b engine for Python requires an older version of Python, so here we use the python/3.7.6 module.

Within a Jupyter notebook, to display inline graphics include the following command in one of the beginning cells:

imatlab_export_fig('print-png')

0.0.7 Mathematica

To install a Mathematica kernel, enter the following commands:

module purge
export PATH=/spack/conda/envs/ood-jupyterlab/bin:$PATH
module load mathematica/12.3
git clone --single-branch --depth 1 <https://github.com/WolframResearch/WolframLanguageForJupyter.git>
cd WolframLanguageForJupyter
./configure-jupyter.wls add

0.0.8 LFortran

LFortran can be installed via a Conda environment. First, set up your shell for Conda — see the Using Conda user guide for instructions.

To install an LFortran kernel, enter the following commands:

module purge
mamba create -n lf
mamba activate lf
mamba install -c conda-forge lfortran
rsync -rlt $CONDA_PREFIX/share/jupyter/kernels/fortran $HOME/.local/share/jupyter/kernels/

0.0.9 Bash

To install a Bash kernel, enter the following commands:

module purge
module load gcc/11.3.0 python/3.11.3
pip install bash_kernel --user
python -m bash_kernel.install --user