Sage Jupyter Kernel

166 views
Skip to first unread message

Luis Finotti

unread,
Jul 27, 2026, 4:35:17 PMJul 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 PMJul 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 PMJul 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 PMJul 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?

Dima Pasechnik

unread,
Aug 1, 2026, 8:59:41 PMAug 1
to sage-s...@googlegroups.com
How do you install Sage into your venv?

Do you do a meson-only build?

I don't think we support doing a "classic" Sage install into a venv (which would mean nesting venv's)




On July 27, 2026 3:35:17 PM CDT, Luis Finotti <luis.f...@gmail.com> wrote:

Luis Finotti

unread,
Aug 2, 2026, 10:22:51 AMAug 2
to sage-support
I compiled sage from source.  Then, I was using Sage as just a notebook kernel when in an venv.

(Can I create different venvs within Sage?  I mean, I know I can install packages with "sage --pip", but I was worried of having problems from installing many packages)

William Stein

unread,
Aug 2, 2026, 11:44:35 AMAug 2
to sage-s...@googlegroups.com
You could also try pip installing sage into any existing python environment as explained here:


--
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 visit https://groups.google.com/d/msgid/sage-support/8c5381bc-9174-46c2-a438-bd09bd9b4518n%40googlegroups.com.


--

Best Regards,
William Stein

CEO, SageMath, Inc.
https://cocalc.com

Luis Finotti

unread,
Aug 2, 2026, 12:41:33 PMAug 2
to sage-support
Interesting...  I will give it a try!  I worry about the disk space taken, but I guess I can spare it for now.

Does it work in Windows?  I don't use Windows, but if this works fine, I might suggest to my students.

Dima Pasechnik

unread,
Aug 2, 2026, 12:57:58 PMAug 2
to sage-s...@googlegroups.com
we now have two ways of building Sage from source, which one have you used?

William Stein

unread,
Aug 2, 2026, 1:05:24 PMAug 2
to sage-s...@googlegroups.com
On Sun, Aug 2, 2026 at 9:41 AM Luis Finotti <luis.f...@gmail.com> wrote:
Interesting...  I will give it a try!  I worry about the disk space taken, but I guess I can spare it for now.


It's going to be about 5GB.  If you want something small, try "pip install sagelite", which is I think under 1GB, but is only a subset of all sage.
 
Does it work in Windows?  
  I don't use Windows, but if this works fine, I might suggest to my students.
 
No. 

However, if you do want to try a new work-in progress partial re-implementation of sage that works 100% genuinely natively on Windows, check out http://github.com/sagemathinc/sagejs/blob/main/README.md

There's a windows binary here https://github.com/sagemathinc/sagejs/releases  (not that I haven't got around to properly signing it yet).  It is:

- small and self contained: 88MB
- installs in a few seconds
- works robustly for what it does
- MacOS (properly signed), and linux are also supported.

It won't right now cover everything in your book, but it probably does cover most of it.   I'll put on the todo list ensuring all examples in your book work...

 - William
 

Luis Finotti

unread,
Aug 2, 2026, 2:48:53 PMAug 2
to sage-support
On Sunday, August 2, 2026 at 12:57:58 PM UTC-4 xxx.com wrote:
we now have two ways of building Sage from source, which one have you used?

Ah, sorry I missed that.  It was, I think, the "classic" way: https://doc.sagemath.org/html/en/installation/source-distro.html  Downaload the tar ball, run configure, and then make. 

Luis Finotti

unread,
Aug 2, 2026, 2:56:37 PMAug 2
to sage-support


On Sunday, August 2, 2026 at 1:05:24 PM UTC-4 help wrote:
On Sun, Aug 2, 2026 at 9:41 AM Luis Finotti <xxx> wrote:
Interesting...  I will give it a try!  I worry about the disk space taken, but I guess I can spare it for now.


It's going to be about 5GB.  If you want something small, try "pip install sagelite", which is I think under 1GB, but is only a subset of all sage.

I tried the sagelite package and it is not bad at all.  With all the packages (inlcuding jupyterlab, MyST, jupyter-book, jupytext, etc.) is 1.5G.

It seems to work relatively well.  When I run cells individually, it seems to be working just fine.  But when I do "run all cells" or "run all cells above", it seems to get stuck at random cells.
 
 
Does it work in Windows?  
  I don't use Windows, but if this works fine, I might suggest to my students.
 
No. 

However, if you do want to try a new work-in progress partial re-implementation of sage that works 100% genuinely natively on Windows, check out http://github.com/sagemathinc/sagejs/blob/main/README.md

There's a windows binary here https://github.com/sagemathinc/sagejs/releases  (not that I haven't got around to properly signing it yet).  It is:

- small and self contained: 88MB
- installs in a few seconds
- works robustly for what it does
- MacOS (properly signed), and linux are also supported.

It won't right now cover everything in your book, but it probably does cover most of it.   I'll put on the todo list ensuring all examples in your book work...

That's great!  I will try to find a Windows computer to try.  (Or maybe a virtual machine.)  I have a video going over step-by-step installing Sage in Windows (with WSL), but some students had difficulty last time.  I've pointed them to Cocalc then, but having a simpler Windows solution would be helpful.

Thank you so much for the support! 

William Stein

unread,
Aug 2, 2026, 3:47:11 PMAug 2
to sage-s...@googlegroups.com
It's still just a Windows command line terminal program (no jupyter or anything yet).  However, I do have plans to release a Jupyter notebook + sagejs combination for windows, which will be very user friendly for students...
 

--
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.

William Stein

unread,
Aug 2, 2026, 6:40:22 PMAug 2
to sage-s...@googlegroups.com
On Sun, Aug 2, 2026 at 11:56 AM Luis Finotti <luis.f...@gmail.com> wrote:

It won't right now cover everything in your book, but it probably does cover most of it.   I'll put on the todo list ensuring all examples in your book work...

That's great!  I will try to find a Windows computer to try.  (Or maybe a virtual machine.)  I have a video going over step-by-step installing Sage in Windows (with WSL), but some students had difficulty last time.  I've pointed them to Cocalc then, but having a simpler Windows solution would be helpful.

Thank you so much for the support! 

Do I have your permission to copy code from your book/notebooks (with clear attribution) into a test suite that is part of the GPL-licensed open source sagejs?  Then I could ensure that everything in the book fully works. 

 -- William

Luis Finotti

unread,
Aug 3, 2026, 10:41:49 AMAug 3
to sage-support
Yes, you do have permission.

If it helps at all, the MyST Makrdown files (generated by Jupytext) are available in GitHub: 


Again, thank you for your help!

William Stein

unread,
Aug 19, 2026, 11:47:18 PM (2 days ago) Aug 19
to sage-support
Hi Luis,

I finally made the first release of sagejs -- 


it includes the code from your book as part of the test suite, so with luck your book can be used with sagejs.

It's easy to install on linux, macos and native windows, and has its own jupyter kernel:

sagejs --install-jupyter-kernel

It's a single self-contained binary and the download is under 100MB.  

Let me know if this is helpful.

--   William

Luis Finotti

unread,
Aug 20, 2026, 10:33:00 AM (2 days ago) Aug 20
to sage-support
Thank you so much for this!

I am trying to get it running on Windows to show my students.  The installation went fine, and I can run "sagejs' from the start menu or from the download/install location.

I have jupyterlab installed in a conda environment (running fine).  I tried running '.\sagejs.exe --install-jupyter-kernel' (from the installation directory) and it had the output: 'spawnSync jupyter ENOENT'.  But the kernel does not show up in Jupyter Lab.

Am I missing anything?

Luis Finotti

unread,
Aug 20, 2026, 10:55:20 AM (2 days ago) Aug 20
to sage-support

Ah, never mind!

I need to run the command inside the sage environment!  It seems to be running now.  I will do some more tests.

Thanks again for this!  I will be really helpful.
On Thursday, August 20, 2026 at 10:33:00 AM UTC-4 Luis Finotti wrote:
Thank you so much for this!

I am trying to get it running on Windows to show my students.  The installation went fine, and I can run "sagejs' from the start menu or from the download/install location.

I have jupyterlab installed in a conda environment (running fine).  I tried running '.\sagejs.exe --install-jupyter-kernel' (from the installation directory) and it had the output: 'spawnSync jupyter ENOENT'.  But the kernel does not show up in Jupyter Lab.

Am I missing anything?

Ah, never mind!

I needed to run the command inside the sage environment!  It seems to be running now.  I will do some more tests.
 

William Stein

unread,
Aug 20, 2026, 5:11:33 PM (2 days ago) Aug 20
to sage-s...@googlegroups.com
Thanks for testing and the update.   Installing the kernel doesn't need to depend on "jupyter" existing; I'll fix it for the next release so it doesn't.


 
 

--
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.
Reply all
Reply to author
Forward
0 new messages