Installing Jupyter Kernels

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 Getting Started with CARC OnDemand user guide.

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.

Python

The default kernel is for Python 3.9.12, based on the modules gcc/11.3.0 python/3.9.12. This kernel is ready to be used when Jupyter is launched. To use other versions of Python, install the ipykernel package and then create a kernel. For example, enter a set of commands like the following:

module purge
module load gcc/8.3.0 python/3.7.6
pip install ipykernel --user
python -m ipykernel install --user --name py376 --display-name "Python 3.7.6"

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 "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.

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.2.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 = "r422", displayname = "R 4.2.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 "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.

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
conda 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
conda activate myenv
mamba install -c conda-forge r-irkernel
Rscript -e "IRkernel::installspec(name = 'r422', displayname = 'R 4.2.2')"

Use a descriptive name for your kernels.

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.

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.

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')

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

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
conda activate lf
mamba install -c conda-forge lfortran
rsync -rlt $CONDA_PREFIX/share/jupyter/kernels/fortran $HOME/.local/share/jupyter/kernels/

Bash

To install a Bash kernel, enter the following commands:

module purge
module load gcc/11.3.0 python/3.9.12
pip install bash_kernel --user
python -m bash_kernel.install --user
Back to top