Trouble getting SageMath up and running (solved)

Hi, I’m having some major trouble in getting a working setup including a SageMath kernel. Did any of you try such a setup of sagemath on TLJH? Any help or pointers would be very much appreciated.

Here’s what I’ve tried so far:

After setting up TLJH as per the docs (on own server, ubuntu 18.04), everything works just fine with admin user “admin” and TLS via letsencrypt. It’s the combination of TLJH and Sage that I can’t get to work.

1st try: using conda (results in sage-8.3).

conda config --add channels conda-forge
sudo conda install sage

Result: everything’s broken, even plain Python3 notebooks are no longer working!
Here’s the relevant log output of journalctl -u jupyter-admin:

Jun 11 21:16:20 littlest-jupyterhub bash[685]: [I 2019-06-11 21:16:20.505 SingleUserNotebookApp handlers:153] Creating new noteb
Jun 11 21:16:20 littlest-jupyterhub bash[685]: [I 2019-06-11 21:16:20.525 SingleUserNotebookApp log:174] 201 POST /user/admin/ap
Jun 11 21:16:20 littlest-jupyterhub bash[685]: [I 2019-06-11 21:16:20.825 SingleUserNotebookApp log:174] 200 GET /user/admin/not
Jun 11 21:16:21 littlest-jupyterhub bash[685]: [I 2019-06-11 21:16:21.556 SingleUserNotebookApp log:174] 200 GET /user/admin/api
Jun 11 21:16:21 littlest-jupyterhub bash[685]: [I 2019-06-11 21:16:21.563 SingleUserNotebookApp log:174] 200 GET /user/admin/api
Jun 11 21:16:21 littlest-jupyterhub bash[685]: [I 2019-06-11 21:16:21.615 SingleUserNotebookApp log:174] 200 GET /user/admin/api
Jun 11 21:16:21 littlest-jupyterhub bash[685]: [I 2019-06-11 21:16:21.755 SingleUserNotebookApp kernelmanager:164] Kernel starte
Jun 11 21:16:21 littlest-jupyterhub bash[685]: [I 2019-06-11 21:16:21.764 SingleUserNotebookApp log:174] 201 POST /user/admin/ap
Jun 11 21:16:21 littlest-jupyterhub bash[685]: [I 2019-06-11 21:16:21.777 SingleUserNotebookApp log:174] 200 GET /user/admin/api
Jun 11 21:16:21 littlest-jupyterhub bash[685]: [I 2019-06-11 21:16:21.805 SingleUserNotebookApp log:174] 200 GET /user/admin/met
Jun 11 21:16:22 littlest-jupyterhub bash[685]: Traceback (most recent call last):
Jun 11 21:16:22 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/runpy.py", line 193, in _run_module_as_main
Jun 11 21:16:22 littlest-jupyterhub bash[685]:     "__main__", mod_spec)
Jun 11 21:16:22 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/runpy.py", line 85, in _run_code
Jun 11 21:16:22 littlest-jupyterhub bash[685]:     exec(code, run_globals)
Jun 11 21:16:22 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/ipykernel_launcher.py", line 1
Jun 11 21:16:22 littlest-jupyterhub bash[685]:     from ipykernel import kernelapp as app
Jun 11 21:16:22 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/ipykernel/__init__.py", line 2
Jun 11 21:16:22 littlest-jupyterhub bash[685]:     from .connect import *
Jun 11 21:16:22 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/ipykernel/connect.py", line 13
Jun 11 21:16:22 littlest-jupyterhub bash[685]:     from IPython.core.profiledir import ProfileDir
Jun 11 21:16:22 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/IPython/__init__.py", line 49,
Jun 11 21:16:22 littlest-jupyterhub bash[685]:     from .terminal.embed import embed
Jun 11 21:16:22 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/IPython/terminal/embed.py", li
Jun 11 21:16:22 littlest-jupyterhub bash[685]:     from IPython.terminal.interactiveshell import TerminalInteractiveShell
Jun 11 21:16:22 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/IPython/terminal/interactivesh
Jun 11 21:16:22 littlest-jupyterhub bash[685]:     from prompt_toolkit.document import Document
Jun 11 21:16:22 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/prompt_toolkit/__init__.py", l
Jun 11 21:16:22 littlest-jupyterhub bash[685]:     from .interface import CommandLineInterface
Jun 11 21:16:22 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/prompt_toolkit/interface.py",
Jun 11 21:16:22 littlest-jupyterhub bash[685]:     from .application import Application, AbortAction
Jun 11 21:16:22 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/prompt_toolkit/application/__i
Jun 11 21:16:22 littlest-jupyterhub bash[685]:     from .application import Application
Jun 11 21:16:22 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/prompt_toolkit/application/app
Jun 11 21:16:22 littlest-jupyterhub bash[685]:     from prompt_toolkit.buffer import Buffer
Jun 11 21:16:22 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/prompt_toolkit/buffer.py", lin
Jun 11 21:16:22 littlest-jupyterhub bash[685]:     from .completion import Completer, Completion, CompleteEvent
Jun 11 21:16:22 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/prompt_toolkit/completion/__in
Jun 11 21:16:22 littlest-jupyterhub bash[685]:     from .base import Completion, Completer, ThreadedCompleter, DummyCompleter, D
Jun 11 21:16:22 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/prompt_toolkit/completion/base
Jun 11 21:16:22 littlest-jupyterhub bash[685]:     from prompt_toolkit.eventloop import generator_to_async_generator, AsyncGener
Jun 11 21:16:22 littlest-jupyterhub bash[685]: ImportError: cannot import name 'generator_to_async_generator'
Jun 11 21:16:24 littlest-jupyterhub bash[685]: [I 2019-06-11 21:16:24.754 SingleUserNotebookApp restarter:110] KernelRestarter:
Jun 11 21:16:25 littlest-jupyterhub bash[685]: Traceback (most recent call last):
Jun 11 21:16:25 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/runpy.py", line 193, in _run_module_as_main
Jun 11 21:16:25 littlest-jupyterhub bash[685]:     "__main__", mod_spec)
Jun 11 21:16:25 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/runpy.py", line 85, in _run_code
Jun 11 21:16:25 littlest-jupyterhub bash[685]:     exec(code, run_globals)
Jun 11 21:16:25 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/ipykernel_launcher.py", line 1
Jun 11 21:16:25 littlest-jupyterhub bash[685]:     from ipykernel import kernelapp as app
Jun 11 21:16:25 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/ipykernel/__init__.py", line 2
Jun 11 21:16:25 littlest-jupyterhub bash[685]:     from .connect import *
Jun 11 21:16:25 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/ipykernel/connect.py", line 13
Jun 11 21:16:25 littlest-jupyterhub bash[685]:     from IPython.core.profiledir import ProfileDir
Jun 11 21:16:25 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/IPython/__init__.py", line 49,
Jun 11 21:16:25 littlest-jupyterhub bash[685]:     from .terminal.embed import embed
Jun 11 21:16:25 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/IPython/terminal/embed.py", li
Jun 11 21:16:25 littlest-jupyterhub bash[685]:     from IPython.terminal.interactiveshell import TerminalInteractiveShell
Jun 11 21:16:25 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/IPython/terminal/interactivesh
Jun 11 21:16:25 littlest-jupyterhub bash[685]:     from prompt_toolkit.document import Document
Jun 11 21:16:25 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/prompt_toolkit/__init__.py", l
Jun 11 21:16:25 littlest-jupyterhub bash[685]:     from .interface import CommandLineInterface
Jun 11 21:16:25 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/prompt_toolkit/interface.py",
Jun 11 21:16:25 littlest-jupyterhub bash[685]:     from .application import Application, AbortAction
Jun 11 21:16:25 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/prompt_toolkit/application/__i
Jun 11 21:16:25 littlest-jupyterhub bash[685]:     from .application import Application
Jun 11 21:16:25 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/prompt_toolkit/application/app
Jun 11 21:16:25 littlest-jupyterhub bash[685]:     from prompt_toolkit.buffer import Buffer
Jun 11 21:16:25 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/prompt_toolkit/buffer.py", lin
Jun 11 21:16:25 littlest-jupyterhub bash[685]:     from .completion import Completer, Completion, CompleteEvent
Jun 11 21:16:25 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/prompt_toolkit/completion/__in
Jun 11 21:16:25 littlest-jupyterhub bash[685]:     from .base import Completion, Completer, ThreadedCompleter, DummyCompleter, D
Jun 11 21:16:25 littlest-jupyterhub bash[685]:   File "/opt/tljh/user/lib/python3.6/site-packages/prompt_toolkit/completion/base
Jun 11 21:16:25 littlest-jupyterhub bash[685]:     from prompt_toolkit.eventloop import generator_to_async_generator, AsyncGener
Jun 11 21:16:25 littlest-jupyterhub bash[685]: ImportError: cannot import name 'generator_to_async_generator'
Jun 11 21:16:26 littlest-jupyterhub bash[685]: [I 2019-06-11 21:16:26.810 SingleUserNotebookApp log:174] 200 GET /user/admin/met
Jun 11 21:16:27 littlest-jupyterhub bash[685]: [I 2019-06-11 21:16:27.768 SingleUserNotebookApp restarter:110] KernelRestarter:

The errors seem to be related to prompt_toolkit and I’ve read about some related breakage, but I’m unsure if this can be fixed. It seems to me that by default prompt_toolkit 2.0.x is installed whereas conda pulls in 1.0.15 in order to satisfy some dependencies.

2nd try after restoring from snapshot of basic working TLJH: using apt (results in sage-8.1)
sudo apt install sagemath
… works just fine, Python3 is still working, Sage kernel is showing up in jupyter, but the kernel can’t be launched. journalctl -u jupyter-admin gives the following:

Jun 11 20:26:19 littlest-jupyterhub bash[297]: [I 2019-06-11 20:26:19.292 SingleUserNotebookApp handlers:153] Creating new notebook in
Jun 11 20:26:19 littlest-jupyterhub bash[297]: [I 2019-06-11 20:26:19.309 SingleUserNotebookApp log:174] 201 POST /user/admin/api/contents (admin@127.0.0.1) 19.05
ms
Jun 11 20:26:20 littlest-jupyterhub bash[297]: [I 2019-06-11 20:26:20.236 SingleUserNotebookApp log:174] 200 GET /user/admin/api/config/notebook?_=1560284779317 (
admin@127.0.0.1) 6.61ms
Jun 11 20:26:20 littlest-jupyterhub bash[297]: [I 2019-06-11 20:26:20.255 SingleUserNotebookApp log:174] 200 GET /user/admin/api/config/common?_=1560284779318 (ad
min@127.0.0.1) 7.92ms
Jun 11 20:26:20 littlest-jupyterhub bash[297]: [I 2019-06-11 20:26:20.314 SingleUserNotebookApp log:174] 200 GET /user/admin/api/contents/Untitled.ipynb?type=note
book&_=1560284779319 (admin@127.0.0.1) 11.80ms
Jun 11 20:26:20 littlest-jupyterhub bash[297]: [I 2019-06-11 20:26:20.453 SingleUserNotebookApp kernelmanager:164] Kernel started: 4901bd41-9039-4a28-a21d-2bbdd9b
a1abd
Jun 11 20:26:20 littlest-jupyterhub bash[297]: [I 2019-06-11 20:26:20.456 SingleUserNotebookApp log:174] 201 POST /user/admin/api/sessions (admin@127.0.0.1) 25.03
ms
Jun 11 20:26:20 littlest-jupyterhub bash[297]: [I 2019-06-11 20:26:20.473 SingleUserNotebookApp log:174] 200 GET /user/admin/api/contents/Untitled.ipynb/checkpoin
ts?_=1560284779320 (admin@127.0.0.1) 6.43ms
Jun 11 20:26:20 littlest-jupyterhub bash[297]: [I 2019-06-11 20:26:20.533 SingleUserNotebookApp log:174] 200 GET /user/admin/metrics (admin@127.0.0.1) 3.30ms
Jun 11 20:26:20 littlest-jupyterhub bash[297]: /opt/tljh/user/bin/python: Error while finding module specification for 'sage.repl.ipython_kernel' (ModuleNotFoundE
rror: No module named 'sage')
Jun 11 20:26:23 littlest-jupyterhub bash[297]: [I 2019-06-11 20:26:23.448 SingleUserNotebookApp restarter:110] KernelRestarter: restarting kernel (1/5), new rando
m ports
Jun 11 20:26:23 littlest-jupyterhub bash[297]: /opt/tljh/user/bin/python: Error while finding module specification for 'sage.repl.ipython_kernel' (ModuleNotFoundE
rror: No module named 'sage')
Jun 11 20:26:25 littlest-jupyterhub bash[297]: [I 2019-06-11 20:26:25.538 SingleUserNotebookApp log:174] 200 GET /user/admin/metrics (admin@127.0.0.1) 4.80ms
Jun 11 20:26:26 littlest-jupyterhub bash[297]: [I 2019-06-11 20:26:26.460 SingleUserNotebookApp restarter:110] KernelRestarter: restarting kernel (2/5), new rando
m ports
Jun 11 20:26:26 littlest-jupyterhub bash[297]: /opt/tljh/user/bin/python: Error while finding module specification for 'sage.repl.ipython_kernel' (ModuleNotFoundE
rror: No module named 'sage')
Jun 11 20:26:29 littlest-jupyterhub bash[297]: [I 2019-06-11 20:26:29.472 SingleUserNotebookApp restarter:110] KernelRestarter: restarting kernel (3/5), new rando
m ports
Jun 11 20:26:29 littlest-jupyterhub bash[297]: /opt/tljh/user/bin/python: Error while finding module specification for 'sage.repl.ipython_kernel' (ModuleNotFoundE
rror: No module named 'sage')

I’m not quite sure what to make of this error message.

Anyway, any help would be very much appreciated! I just hope that I won’t have to go the route of a full manual setup of some kind of enterprise grade setup where every user gets its own docker container etc. That would be overkill for my humble needs.

Full disclosure: For testing purposes my setup of TLJH is actually running in a privileged LXD container and not on bare metal. But that shouldn’t make a difference. (After all it’s not docker, but rather a full OS inside the container.)

This has been straightened out. See here: https://github.com/conda-forge/sage-feedstock/issues/29

So in essence it’s now sufficient to open a terminal and run the following:

sudo -E conda create -n sage sage=8.8.rc1
sudo -E conda install nb_conda_kernels

SageMath will then show up in the available kernels list. I just don’t know how to add a SageMath kernel spec for this newly created conda env without resorting to nb_conda_kernels. (It adds spurious kernels that I don’t really want, e.g. the Python kernel from the Sage env.)