Installing Sagemath Kernel for Jupyter

Sagemath
Jupyter
Python
Published

October 6, 2021

In this post we want to show how to install a sagemath kernel for jupyter so that we can use it with our system jupyter. My operating system is Ubuntu 20.04 and the latest version in this moment of writing is Sagemath 9.3

alias sage=/home/USERNAME/usrlocal/sage-9.3-Ubuntu_20.04-x86_64/SageMath/sage
export SAGE_ROOT="/home/USERNAME/usrlocal/sage-9.3-Ubuntu_20.04-x86_64/SageMath/"

In my case I had to do the following to make it run.

  1. First of all, my system wide default python (I run Ubuntu 20.04) was still python2.7 so I wanted to change to python3. After googling for a while the following aworked for me:
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
  1. I had to update pip to the latest version.
  2. We can now install our preferred jupyter notebook. I installed many using the official docs
    pip install notebook
    pip install jupyterlab
    pip install voila
  1. Now we can run the following to add the kernel:
sudo jupyter kernelspec install ./local/share/jupyter/kernels/sagemath #find the right path for you
  1. Finally, running jupyter-notebook or jupyter-lab from the command line allows for the following

Kernels in Jupyter-notebook Kernels in Jupyter-lab