Is there a way to use Sage's Jupyter outside the sage shell ?

91 views
Skip to first unread message

Emmanuel Charpentier

unread,
Apr 8, 2024, 2:16:45 PMApr 8
to sage-support

Setup : Sage 10.4.beta1 running on Ubuntu 22.04 LTS under WSL2 in Windows 11 (don’t get me started…). I also installed emacs and its juyter package, which is able to use Sage-installed kernels … when emacs is started from the Sage shell. [ Yes, there is a point to this…]

What I want to do is to be able to use these Sage-installed kernels from outside the Sage shell environment, thus avoiding to duplicate the Sage Jupyter installation. In other words, I want a jupyter command that is able to finfd the Sage-instaled kernels in their correct environment.

Is there any way to do that ?

Nils Bruin

unread,
Apr 8, 2024, 6:21:57 PMApr 8
to sage-support
If you run `jupyter --paths` and  `sage -sh <<<"jupyter --paths"` you see the difference in paths. The relevant ones for you are probably the sage-specific ones
$SAGE-LOCAL/var/lib/sage/venv-python3.10/share/jupyter
Whatever is there will get picked up by sage's jupyter but, naturally, not by your standard jupyter.
So the kernels that live there could be copied to a location that is accessed by your system jupyter:
$HOME/.local/share/jupyter
or something like that.

Note that the files there might need some surgery, because starting those kernels probably needs to happen through sage's python (or at least its venv); similar to how to get the sage kernel working in a system jupyter.

Dima Pasechnik

unread,
Apr 8, 2024, 8:24:45 PMApr 8
to sage-s...@googlegroups.com
Actually, the best way to solve this would be to get rid of Jupyter as a part of Sage the distribution.
Then one can install these kernels in a normal Jupyter way - without it being a kind of
afterthought 2nd class citizen way.
No project I know, apart from Sage, vendors Jupyter. Vendoring Jupyter is just a needless bloat.

Dima 

--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/0d7f8312-478b-40b5-8943-57388fa22bc5n%40googlegroups.com.

Emmanuel Charpentier

unread,
Apr 9, 2024, 8:17:17 AMApr 9
to sage-support

Le mardi 9 avril 2024 à 02:24:45 UTC+2, Dima Pasechnik a écrit :

[ Snip… ]

Actually, the best way to solve this would be to get rid of Jupyter as a part of Sage the distribution.

Agreed. Since I “seriously” configured Sage a loooong time ago, I missed the rise of the .configure options allowing for using the system’s Jupyter. As far as I understand it, I’ll have to install Ubuntu’s (=Debian’s) Jupyter, pipx and install Jupyterlab in a venv. Will this solve my problem ? Stay tuned…

Then one can install these kernels in a normal Jupyter way - without it being a kind of
afterthought 2nd class citizen way.
No project I know, apart from Sage, vendors Jupyter. Vendoring Jupyter is just a needless bloat.

The important word is “is” (i.e. not “was“) : ISTR that a (not so) long time ago, Sages motto was “batteries included”, which implied the bundling of anything Sage could use in Sage-the-distribution (including some interesting kitchen sinks…). This “philosophy” has changed, but Sage’s construction still lags behind (and so does my knowledge of the installation system…).

Nathan Dunfield

unread,
Apr 9, 2024, 1:20:45 PMApr 9
to sage-support
On Monday, April 8, 2024 at 5:21:57 PM UTC-5 Nils Bruin wrote:
If you run `jupyter --paths` and  `sage -sh <<<"jupyter --paths"` you see the difference in paths. The relevant ones for you are probably the sage-specific ones
$SAGE-LOCAL/var/lib/sage/venv-python3.10/share/jupyter
Whatever is there will get picked up by sage's jupyter but, naturally, not by your standard jupyter.
So the kernels that live there could be copied to a location that is accessed by your system jupyter:
$HOME/.local/share/jupyter
or something like that.

Note that the files there might need some surgery, because starting those kernels probably needs to happen through sage's python (or at least its venv); similar to how to get the sage kernel working in a system jupyter.

The Sage binary installer for macOS optionally installs the Sage Jupyter kernels in a location that an arbitrary Jupyter will search by default, and in that case the JSON kernel file just looks like:

{"argv": ["/var/tmp/sage-10.3-current/venv/bin/sage", "--python", "-m", 
              "sage.repl.ipython_kernel", "-f", "{connection_file}"], 
 "display_name": "SageMath 10.3",
 "language": "sage"}

I think it will work as long as your have the full path to Sage in the venv as part of argv.

Best,

Nathan

Marc Culler

unread,
Apr 9, 2024, 2:18:05 PMApr 9
to sage-support
If I understand your question correctly, the answer is yes.  All that you need to do is to copy the sage kernel spec directory into /usr/local/share/jupyter/kernels.  If you have installed jupyter in a python venv then the jupyter command in the venv will always check for kernels in that directory.  By the sage kernel spec directory I mean:
sage/venv/share/jupyter/kernels/sagemath
the kernel.json file in that directory should contain the absolute path to the sage  executable in your installation of sage as the first item in the "varg" list.

- Marc

Matthias Koeppe

unread,
Apr 15, 2024, 3:19:17 AMApr 15
to sage-support

Henri Girard

unread,
Apr 15, 2024, 8:46:33 AMApr 15
to sage-s...@googlegroups.com

I don't understand what you mean , but there is maybe a way you can use it as I do in vs code ?

--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.

Dima Pasechnik

unread,
Apr 15, 2024, 9:29:45 AMApr 15
to sage-s...@googlegroups.com
On Mon, Apr 15, 2024 at 1:46 PM Henri Girard <henri....@gmail.com> wrote:

I don't understand what you mean , but there is maybe a way you can use it as I do in vs code ?

Le 15/04/2024 à 09:19, Matthias Koeppe a écrit :
Yes, this is documented in https://doc.sagemath.org/html/en/installation/launching.html#setting-up-sagemath-as-a-jupyter-kernel-in-an-existing-jupyter-notebook-or-jupyterlab-installation

The instructions given there for using VS Code+WSL there should be adapted to using
VS Code+local Sage, and VS Code + (non-WSL remote Sage install).

It seems that Jupyter extension in VS Code packages more goodies than the generic Jupyter install,
in particular various nbextensions are there.
 


On Monday, April 8, 2024 at 11:16:45 AM UTC-7 Emmanuel Charpentier wrote:

Setup : Sage 10.4.beta1 running on Ubuntu 22.04 LTS under WSL2 in Windows 11 (don’t get me started…). I also installed emacs and its juyter package, which is able to use Sage-installed kernels … when emacs is started from the Sage shell. [ Yes, there is a point to this…]

What I want to do is to be able to use these Sage-installed kernels from outside the Sage shell environment, thus avoiding to duplicate the Sage Jupyter installation. In other words, I want a jupyter command that is able to finfd the Sage-instaled kernels in their correct environment.

Is there any way to do that ?

--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/e526ffb3-bebe-49af-9f1d-075b0aacff3an%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.

Henri Girard

unread,
Apr 15, 2024, 2:31:23 PMApr 15
to sage-s...@googlegroups.com

I use many vscode with sagemath-9.2 (windows installer) and sagemath 10.4beta 2wsl2

i start sage copy the address from the terminal then I paste it in serveur ans it finds the localhost this is interesting in w11 because i can start sage directly in code so I can see what is in ipynb because I have done tons of it and I never remenber what's inside !

Reply all
Reply to author
Forward
0 new messages