Sage Jupyter Kernel

45 views
Skip to first unread message

Luis Finotti

unread,
Jul 27, 2026, 4:35:17 PM (4 days ago) Jul 27
to sage-support
(This is related to a previous post: https://groups.google.com/g/sage-support/c/SkogHFVhyf0)

I've written an online text on cybersecurity using Sage (https://luisfinotti.org/pcimc/00-Intro.html).  It was built using MyST Markdown.

I am teaching a course using it and would like to have Sage running in a virtual environment where I have myst and other related packages installed.  That way I can have the nice formatted text from the book (with MyST) and run the sage cells as I teach.

I used to be able to do it by making the Sage jupyter kernel available following https://doc.sagemath.org/html/en/installation/launching.html#setting-up-sagemath-as-a-jupyter-kernel-in-an-existing-jupyter-notebook-or-jupyterlab-installation.  Basically, I could run something like:

ln -s $(sage -sh -c 'ls -d $SAGE_ROOT/venv/share/jupyter/kernels/sagemath') $HOME/.local/share/jupyter/kernels/sagemath

But $SAGE_VENV/share/jupyter/kernels/sagemath does not seem to exist anymore, so this method does not work anymore.

Is there a way of doing this (having the Sage Jupyter Kernel available for a virtual environment) now?

If not, what would be a proper way of doing this?  I suppose I could run something like 

sage --pip install <package>

for every package I need.  But it seems like it would "polute" Sage's default environment.

Any suggestions?  (I desperately need to have this working soon.)

Thanks,

Luis

Dima Pasechnik

unread,
Jul 28, 2026, 12:06:20 PM (3 days ago) Jul 28
to sage-s...@googlegroups.com
The sanest way to set up a Jupyter kernel is to have Jupyter(lab) installed on the machine (or in a venv) and 
run 

    jupyter kernelspec install --name=sagemath --user $SAGEROOT/build/sage-distro/src/sage

which installs the Sage's Jupyter kernel in the correct (for this jupyter installation!) location

This is also done when sagelib is installed in the Sage's "classic" installation, but where the kernel ends up is 
iffy. It might mean that it's only available via Sage's jupyterlab, which might be not what you want.


HTH
Dima

Luis Finotti

unread,
Jul 28, 2026, 3:09:49 PM (3 days ago) Jul 28
to sage-support
Thanks for the help!  Unfortunately, it does not seem to work.  When choosing the Sage kernel, I get:

[snip]
[W 2026-07-28 15:08:24.729 ServerApp] Notebook Untitled.ipynb is not trusted
[E 2026-07-28 15:08:24.749 LabApp] Fail to get yarn configuration. Expecting value: line 1 column 1 (char 0)
[I 2026-07-28 15:08:24.756 LabApp] Build is up to date
/usr/bin/python3: Error while finding module specification for 'sage.repl.ipython_kernel' (ModuleNotFoundError: No m
odule named 'sage')
[I 2026-07-28 15:08:29.452 ServerApp] Kernel started: a33bfdf2-3fdc-4350-9bac-b4d539a9d34d
[I 2026-07-28 15:08:32.441 ServerApp] AsyncIOLoopKernelRestarter: restarting kernel (1/5), new random ports
/usr/bin/python3: Error while finding module specification for 'sage.repl.ipython_kernel' (ModuleNotFoundError: No m
odule named 'sage')
[I 2026-07-28 15:08:35.455 ServerApp] AsyncIOLoopKernelRestarter: restarting kernel (2/5), new random ports
/usr/bin/python3: Error while finding module specification for 'sage.repl.ipython_kernel' (ModuleNotFoundError: No m
odule named 'sage')
[I 2026-07-28 15:08:38.471 ServerApp] AsyncIOLoopKernelRestarter: restarting kernel (3/5), new random ports
/usr/bin/python3: Error while finding module specification for 'sage.repl.ipython_kernel' (ModuleNotFoundError: No m
odule named 'sage')
[I 2026-07-28 15:08:41.487 ServerApp] AsyncIOLoopKernelRestarter: restarting kernel (4/5), new random ports
/usr/bin/python3: Error while finding module specification for 'sage.repl.ipython_kernel' (ModuleNotFoundError: No m
odule named 'sage')
[I 2026-07-28 15:08:44.502 ServerApp] AsyncIOLoopKernelRestarter: restarting kernel (5/5), new random ports
/usr/bin/python3: Error while finding module specification for 'sage.repl.ipython_kernel' (ModuleNotFoundError: No m
odule named 'sage')
[W 2026-07-28 15:08:47.520 ServerApp] AsyncIOLoopKernelRestarter: restart failed
[W 2026-07-28 15:08:47.521 ServerApp] Kernel a33bfdf2-3fdc-4350-9bac-b4d539a9d34d died, removing from map.
[W 2026-07-28 15:09:44.522 ServerApp] Timeout waiting for kernel_info reply from a33bfdf2-3fdc-4350-9bac-b4d539a9d34
d
[W 2026-07-28 15:09:44.522 ServerApp] Timeout waiting for kernel_info reply from a33bfdf2-3fdc-4350-9bac-b4d539a9d34
d
[E 2026-07-28 15:09:44.522 ServerApp] Uncaught exception GET /api/kernels/a33bfdf2-3fdc-4350-9bac-b4d539a9d34d/chann
els?session_id=31a73cd4-8cdd-478c-8df3-98704c961d97 (::1)
   HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/api/kernels/a33bfdf2-3fdc-4350-9ba
c-b4d539a9d34d/channels?session_id=31a73cd4-8cdd-478c-8df3-98704c961d97', version='HTTP/1.1', remote_ip='::1')
   Traceback (most recent call last):
     File "/usr/lib/python3/dist-packages/tornado/web.py", line 1812, in _execute
       result = await result
                ^^^^^^^^^^^^
     File "/usr/lib/python3/dist-packages/jupyter_server/services/kernels/websocket.py", line 66, in get
       await super().get(kernel_id=kernel_id)
     File "/usr/lib/python3/dist-packages/tornado/websocket.py", line 273, in get
       await self.ws_connection.accept_connection(self)
     File "/usr/lib/python3/dist-packages/tornado/websocket.py", line 863, in accept_connection
       await self._accept_connection(handler)
     File "/usr/lib/python3/dist-packages/tornado/websocket.py", line 903, in _accept_connection
       self.selected_subprotocol = handler.select_subprotocol(subprotocols)
                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
     File "/usr/lib/python3/dist-packages/jupyter_server/services/kernels/websocket.py", line 88, in select_subprot
ocol
       preferred_protocol = self.connection.kernel_ws_protocol
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   AttributeError: 'NoneType' object has no attribute 'kernel_ws_protocol'
[E 2026-07-28 15:09:44.527 ServerApp] {
     "Host": "localhost:8888",
     "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/
537.36"
   }
[E 2026-07-28 15:09:44.527 ServerApp] 500 GET /api/kernels/a33bfdf2-3fdc-4350-9bac-b4d539a9d34d/channels?session_id=
31a73cd4-8cdd-478c-8df3-98704c961d97 (93473913a7f44df2ba4669f8fbe533cd@::1) 75063.20ms referer=None
[E 2026-07-28 15:09:44.527 ServerApp] Uncaught exception GET /api/kernels/a33bfdf2-3fdc-4350-9bac-b4d539a9d34d/chann
els?session_id=fb80a1d8-a306-4448-baea-021f7d7f3152 (127.0.0.1)
   HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/api/kernels/a33bfdf2-3fdc-4350-9ba
c-b4d539a9d34d/channels?session_id=fb80a1d8-a306-4448-baea-021f7d7f3152', version='HTTP/1.1', remote_ip='127.0.0.1')
   Traceback (most recent call last):
     File "/usr/lib/python3/dist-packages/tornado/web.py", line 1812, in _execute
       result = await result
                ^^^^^^^^^^^^
     File "/usr/lib/python3/dist-packages/jupyter_server/services/kernels/websocket.py", line 66, in get
       await super().get(kernel_id=kernel_id)
     File "/usr/lib/python3/dist-packages/tornado/websocket.py", line 273, in get
       await self.ws_connection.accept_connection(self)
     File "/usr/lib/python3/dist-packages/tornado/websocket.py", line 863, in accept_connection
       await self._accept_connection(handler)
     File "/usr/lib/python3/dist-packages/tornado/websocket.py", line 903, in _accept_connection
       self.selected_subprotocol = handler.select_subprotocol(subprotocols)
                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
     File "/usr/lib/python3/dist-packages/jupyter_server/services/kernels/websocket.py", line 88, in select_subprot
ocol
       preferred_protocol = self.connection.kernel_ws_protocol
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   AttributeError: 'NoneType' object has no attribute 'kernel_ws_protocol'
[E 2026-07-28 15:09:44.529 ServerApp] {
     "Host": "localhost:8888",
     "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/
537.36"
   }
[E 2026-07-28 15:09:44.529 ServerApp] 500 GET /api/kernels/a33bfdf2-3fdc-4350-9bac-b4d539a9d34d/channels?session_id=
fb80a1d8-a306-4448-baea-021f7d7f3152 (93473913a7f44df2...@127.0.0.1) 74759.21ms referer=None



Any ideas?

Luis Finotti

unread,
Jul 30, 2026, 4:58:32 PM (15 hours ago) Jul 30
to sage-support
In my laptop, running Debian Trixie/Stable, I could install sage-10.7, which still had the sage kernel at $SAGE_ROOT/venv/share/jupyter/kernels/sagemath, so I can use it with a different environment.  (It's not ideal, but it works.)

So, I tried to compile 10.7 in my desktop, running Debian Sid, and I could not compile it...  The log is available at https://luisfinotti.org/misc/install.log.

Any ideas?
Reply all
Reply to author
Forward
0 new messages