How to install sagemath kernel in Jupyter

The answer suggesting

$ jupyter kernelspec install --user <path to SageMath/local/share/jupyter/kernels/sagemath>

works only if you provide the environment variable SAGE_ROOT in the kernel spec. This requires adding an "env" item to the kernel.json. The line that must be added is:

"env":{"SAGE_ROOT":"<Path to sage root>"}

An example specific to an installed mac app for version 8.7 is:

"env":{"SAGE_ROOT":"/Applications/SageMath-8.7.app/Contents/Resources/sage"}

See this question for general information and a complete example.


I have just installed SageMath kernel on my existing Jupyter installation. It's super easy.

$ sudo jupyter kernelspec install ./SageMath/local/share/jupyter/kernels/sagemath

Where SageMath is your root sagemath directory. Hope this will help someone.

If you don't have sudo rights you won't be able to install system-wide, but you can still install for yourself using the --user flag:

$ jupyter kernelspec install --user ./SageMath/local/share/jupyter/kernels/sagemath

You are going about it backwards; Sage includes the Jupyter notebook inside of it, and you can use it with that kernel that way. (As well as others.) Use

$ sage --notebook ipython

I believe. See also here.

(I think there are also some people who have had success redirecting their Jupyter to "see" the Sage kernel by editing some file or configuration. On Arch Linux this is apparently supported ... ?)


I know this is an old question, but I stumbled onto it and ended up making a docker container to accomplish this for anyone who is interested.

https://hub.docker.com/r/sharptrick/sage-notebook

The dockerfile may be of interest as it has explicit instructions which install the kernel to the official "jupyter/minimal-notebook".

https://github.com/sharpTrick/sage-notebook/blob/master/Dockerfile