Difficulties setting up a kernel for jupyterlab in Windows

I recently downloaded SageMath for Windows and installed it. I have my habits in jupyterlab and wanted to add it as a new kernel, but encountered some difficulties.

Locating the error

I followed instruction steps given at wiki.sagemath.org/SageWindows . When trying to start the kernel from a jupyterlab server I was met with an error message beginning with:

Failed to run command: ['/opt/sagemath-9.2/local/bin/sage', '--python', '-m', 'sage.repl.ipython_kernel', '-f', '[...]']

where [...] stands for the path to the kernel file. Considering that the shortcuts created at SageMath installation produced the expected result I compared it to the kernel specification and learned that this path specification is invalid in Windows and furthermore that the file trying to be run cannot be directly interpreted by Windows as an executable. The shortcuts work around it by running such commands in a mintty terminal.

Trying to patch

Following this example I changed the kernel specifications with:"argv": ["C:/Program Files/Sagemath 9.2/runtime/bin/mintty","/opt/sagemath-9.2/local/bin/sage", "--python", "-m", "sage.repl.ipython_kernel", "-f", "{connection_file}"]. This was met with relative success as jupyter recognized this as a valid kernel specification, yet upon startup the kernel would not run, mintty windows would pop up and close while the jupyterlab server considered the kernel dead:

[I 2021-10-12 16:51:58.642 ServerApp] Kernel started: 54b584e9-bbb1-4f80-a69b-f42cab5ec102

[I 2021-10-12 16:52:01.638 ServerApp] AsyncIOLoopKernelRestarter: restarting kernel (1/5), new random ports

[I 2021-10-12 16:52:04.755 ServerApp] AsyncIOLoopKernelRestarter: restarting kernel (2/5), new random ports

[I 2021-10-12 16:52:07.806 ServerApp] AsyncIOLoopKernelRestarter: restarting kernel (3/5), new random ports

[I 2021-10-12 16:52:10.840 ServerApp] AsyncIOLoopKernelRestarter: restarting kernel (4/5), new random ports

[W 2021-10-12 16:52:13.892 ServerApp] AsyncIOLoopKernelRestarter: restart failed

[W 2021-10-12 16:52:13.892 ServerApp] Kernel 54b584e9-bbb1-4f80-a69b-f42cab5ec102 died, removing from map.

Trying to change the arguments with the configfiles for sage console, shell or notebook only changed evanescent mintty windows into as many mintty terminals running sage interpreter/shell/notebook server as attempts by jupyter to restart the kernel.

Where help is welcome

I do not now if there is but seek a way to get the sage.repl.ipython_kernel running on its own and/or link it to jupyterlab to use it as a kernel for any notebook. The easiest for me would be to have everything as one Windows command to put into the "argv" key of the kernel specification. It would also be possible to include it in future builds of SageMath for Windows.

If impossible maybe there is a way to build a standalone executable to be linked in the kernelspec but I do not know the first thing about building this and linking it to the SageMath libs and resources.

Thanks in advance for any useful answer!

Reading mintty's manual I found I could use the option -h always to get the popping up windows to stay open. I am now able to read the error messages:

/usr/bin/env: 'bash': No such file or directory

C:/Program Files/SageMath 9.2/runtime/bin/bash: Exit 127.

Reading the sage files in the SAGE_ROOT and SAGE_LOCAL. My understanding is that the first one does some setting up and input sanitation before invoking the second one. This is where the code breaks with the shebang #!usr/bin/env bash. I tried having the root sage be launched through C:/Program Files/SageMath 9.2/runtime/bin/bash as the shortcuts do but it didn't change much. Yet when the shortcuts start sage there is no such error, which means that somehow mintty using /opt/sagemath-9.2/local/bin/sage under the -c option sets up bash in a path variable, at least form the local sage's point of view.

I do not understand how this happens and would like some help to recreate it.

edit retag close merge delete