Ask Your Question
1

SageMath Jupyter kernel not listed after installing Sage from source

asked 2023-06-06 06:53:29 +0100

toni gravatar image

updated 2024-08-26 11:17:59 +0100

FrédéricC gravatar image

I will list a bunch of potentially relevant info:

  1. I am running Ubuntu 2204.2.33.0 on WSL

  2. I had installed sage initially using the apt as sudo apt install sagemath

  3. I had managed to run Jupyter NB with three different kernels: Rstats (IR), python, sagemath

  4. I decided to install SageMath from source, starting with removing the installed version with sudo apt-get --purge remove sagemath

  5. I have now SageMath version 10.0 installed. However its kernel does not appear as an option for Jupyter NB.

  6. If I run the command jupyter kernelspec list I get back:

└─$jupyter kernelspec list Available kernels: ir
/home/toni/.local/share/jupyter/kernels/ir python3
/home/toni/.local/share/jupyter/kernels/python3

I have tried creating a directory inside /home/toni/.local/share/jupyter/kernels called sagemath and running sudo jupyter kernelspec install ./SageMath/local/share/jupyter/kernels/sagemath, which doesn't seem to make sense how it would work, but it was a suggestion on a this answer, and I am probably applying it incorrectly. That gave me the error message: Jupyter command jupyter-kernelspec not found.

I have SageMath under a different directory: /home/toni/sage, and I don't see Jupyter inside the subdirectory /home/toni/sage/local/share


I THOUGHT I HAD SOLVED THIS, BUT NO...

With the solution I posted, i.e.

I got it going by simply running:

sudo apt install sagemath-jupyter

Now:

└─$jupyter kernelspec list
Available kernels:
  ir          /home/toni/.local/share/jupyter/kernels/ir
  python3     /home/toni/.local/share/jupyter/kernels/python3
  sagemath    /usr/share/jupyter/kernels/sagemath

I did get the kernel for Sage on Jupyter NB. However, I just realized that the kernel if for Sage 9.5, not Sage 10!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2023-06-06 18:24:07 +0100

Emmanuel Charpentier gravatar image

updated 2023-06-06 18:39:08 +0100

Building sage from source builds a specific Jupyter installation, living somewhere under `$SAGE_ROOT. Compare :

charpent@zen-book-flip:~$ sage -sh -c "which jupyter"
/usr/local/sage-10/local/var/lib/sage/venv-python3.11/bin/jupyter

i. e. Sage's Jupyter, with :

charpent@zen-book-flip:~$ which jupyter
/usr/bin/jupyter

i. e. system's Jupyter. In particular, when you run sage -n jupyter, what is run is indeed Sage's Jupyter.

This results from an old "Sage comes with batteries included" policy that turned Sage in some mini-distribution (hence the nickname "Sage-the-distribution") you see on sage-devel...). This eased the adaptation oof various math software and system as Sage's components. But entailed a lot of work and a tendency tof Sage's versions o drift apart from their upstream origins.

This policy is now counterbalanced by a serious modularization effort : more and more Sage components can use their system's counterpart. This can be done for Jupyter (although it is not yet the default). You can instal Sage's kernel in the system's Jupyter ; see this part of Sage's documentation.

Or you could also install Sage's Jupyter as your default one, and install other kernels in this installation. Choose your poison...

In Debian's case, keeping Sage's Jupyter may be ise : Debian recently choose a "managed setup" which forbids you to sudo pip instal <whatever to install Python packages systemwide,and requires you to apt install python3-<whatever> systemwide. You can still install a not-yet-Debian-packaged extension with pipx install <whatever> on a user-per-user basis.

Nototious case : the Jupyter Lab notebook :

charpent@zen-book-flip:~$ pip install jupyterlab
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.


If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.

If you wish to install a non-Debian packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.

See /usr/share/doc/python3.11/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages

The venv solution directly competes with Sage (that's roughly what sage -sh does...). Keeping Sage's Jupyter may save you a couple of headaches...

HTH,

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-06-06 06:53:29 +0100

Seen: 1,493 times

Last updated: Jun 06 '23