Binder and Sagemath

From the past I have been using successfully Sagemath with Binder. Following this discussion in sage-devel forum, it seems that now Sagemath does not work. I tried one previously successful page with no success.

Thansk, Enrique.

Retried again. These are the logs:

Waiting for build to start…
Built image, launching…
Launching server…
Server requested
2021-10-09T09:06:12.557710Z [Normal] Successfully assigned turing/jupyter-enriqueartal-2dqu-2dformsingularity-2dhak2yp3i to aks-user-14930255-vmss00000j
2021-10-09T09:06:13Z [Normal] Container image “jupyterhub/mybinder.org-tc-init:2020.12.4-n655.hfe65496” already present on machine
2021-10-09T09:06:13Z [Normal] Created container tc-init
2021-10-09T09:06:13Z [Normal] Started container tc-init
2021-10-09T09:06:14Z [Normal] Pulling image “turingmybinder/binder-prod-r2d-g5b5b759-enriqueartal-2dquadraticformsingularity-5b0133:3af764e78f2ec3a2bd5b10e5713be2222f9c2202”
2021-10-09T09:07:04Z [Normal] Successfully pulled image “turingmybinder/binder-prod-r2d-g5b5b759-enriqueartal-2dquadraticformsingularity-5b0133:3af764e78f2ec3a2bd5b10e5713be2222f9c2202”
2021-10-09T09:07:10Z [Normal] Created container notebook
2021-10-09T09:07:10Z [Normal] Started container notebook
Spawn failed: Timeout
Launch attempt 1 failed, retrying…
Server requested
2021-10-09T09:11:16.991402Z [Normal] Successfully assigned turing/jupyter-enriqueartal-2dqu-2dformsingularity-2d86zjjq1g to aks-user-14930255-vmss00000j
2021-10-09T09:11:17Z [Normal] Container image “jupyterhub/mybinder.org-tc-init:2020.12.4-n655.hfe65496” already present on machine
2021-10-09T09:11:18Z [Normal] Created container tc-init
2021-10-09T09:11:18Z [Normal] Started container tc-init
2021-10-09T09:11:18Z [Normal] Container image “turingmybinder/binder-prod-r2d-g5b5b759-enriqueartal-2dquadraticformsingularity-5b0133:3af764e78f2ec3a2bd5b10e5713be2222f9c2202” already present on machine
2021-10-09T09:11:18Z [Normal] Created container notebook
2021-10-09T09:11:19Z [Normal] Started container notebook
Spawn failed: Timeout
Launch attempt 2 failed, retrying…
Server requested
2021-10-09T09:16:27.056172Z [Normal] Successfully assigned turing/jupyter-enriqueartal-2dqu-2dformsingularity-2d719v46if to aks-user-14930255-vmss00000j
2021-10-09T09:16:27Z [Normal] Container image “jupyterhub/mybinder.org-tc-init:2020.12.4-n655.hfe65496” already present on machine
2021-10-09T09:16:28Z [Normal] Created container tc-init
2021-10-09T09:16:28Z [Normal] Started container tc-init
2021-10-09T09:16:28Z [Normal] Container image “turingmybinder/binder-prod-r2d-g5b5b759-enriqueartal-2dquadraticformsingularity-5b0133:3af764e78f2ec3a2bd5b10e5713be2222f9c2202” already present on machine
2021-10-09T09:16:28Z [Normal] Created container notebook
2021-10-09T09:16:28Z [Normal] Started container notebook

It works with sagemathinc/cocalc:latest

1 Like

You can find an example of using Sage with Binder at

It used to be docker based; however the docker image were
not functional any more, and in the mean time conda packaging
of sage has matured a lot. Also generally speaking conda is
preferable for binder.

So I switched recently to a conda-based binder configuration. It’s
not as flexible as the previous configuration though (e.g. it does
not come with kernels for GAP, Singular, …).

1 Like

Is it possible to use this approach in mybinder.org?

Yes: you can try it by following the binder link in the README of
the above repo.

To apply it to your own repo, it should be enough to copy over
the environment.yml file.

2 Likes

I have tried the binder link of the above repo, it launches JupyterNotebook, but the Sagemath kernel is not connected (restart does not help).
It behaves the same also for my repo with the same environment.yml.
Do you know how to fix this? Thanks.

@Legersky, the SageMath 9.5 kernel is working on the first demo page in sessions for me.

Minor issue noted while looking into it:
The only thing I see not working correctly on the first page that comes up as the session launches, at this moment, is the ipywidget invoked from the penultimate code cell IntSlider(3,1,5) isn’t rendering. It just displays the text 𝙸𝚗𝚝𝚂𝚕𝚒𝚍𝚎𝚛(𝚟𝚊𝚕𝚞𝚎=𝟹, 𝚖𝚊𝚡=𝟻, 𝚖𝚒𝚗=𝟷) in the output area. ipywidgets being added to the environment.yml file should fix that, especially since running %conda install ipywidgets in the session and re-running the cells involved again fixed it.

1 Like

I had the same problem in my repo and with sage-binder-env. The following happens when running sage at the terminal:


IPython post-mortem report

{‘commit_hash’: ‘8636493’,
‘commit_source’: ‘installation’,
‘default_encoding’: ‘UTF-8’,
‘ipython_path’: ‘/srv/conda/envs/notebook/lib/python3.7/site-packages/IPython’,
‘ipython_version’: ‘7.32.0’,
‘os_name’: ‘posix’,
‘platform’: ‘Linux-5.4.188±x86_64-with-debian-buster-sid’,
‘sys_executable’: ‘/srv/conda/envs/notebook/bin/python’,
‘sys_platform’: ‘linux’,
‘sys_version’: '3.7.12 | packaged by conda-forge | (default, Oct 26 2021, ’
‘06:08:53) \n’
‘[GCC 9.4.0]’}



Crash traceback:



ImportError Python 3.7.12: /srv/conda/envs/notebook/bin/python
Tue Jul 26 09:45:36 2022
A problem occurred executing Python code. Here is the sequence of function
calls leading up to the error, with the most recent (innermost) call last.
/srv/conda/envs/notebook/bin/sage-ipython in
1 #!/srv/conda/envs/notebook/bin/python
2 # -- coding: utf-8 --
3 “”"
4 Sage IPython startup script.
5 “”"
6
7 # Display startup banner. Do this before anything else to give the user
8 # early feedback that Sage is starting.
9 from sage.misc.banner import banner
10 banner()
11
12 from sage.repl.interpreter import SageTerminalApp
13
14 app = SageTerminalApp.instance()
—> 15 app.initialize()
global app.initialize = <bound method TerminalIPythonApp.initialize of <sage.repl.interpreter.SageTerminalApp object at 0x7f6ab0607050>>
16 app.start()

/srv/conda/envs/notebook/lib/python3.7/site-packages/traitlets/config/application.py in inner(app=<sage.repl.interpreter.SageTerminalApp object>, *args=(), **kwargs={})
73 else:
74 raise ValueError(“Unsupported value for environment variable: ‘TRAITLETS_APPLICATION_RAISE_CONFIG_FILE_ERROR’ is set to ‘%s’ which is none of {‘0’, ‘1’, ‘false’, ‘true’, ‘’}.”% _envvar )
75
76
77 def catch_config_error(method):
78 “”“Method decorator for catching invalid config (Trait/ArgumentErrors) during init.
79
80 On a TraitError (generally caused by bad config), this will print the trait’s
81 message, and exit the app.
82
83 For use on init methods, to prevent invoking excepthook on invalid input.
84 “””
85 @functools.wraps(method)
86 def inner(app, *args, **kwargs):
87 try:
—> 88 return method(app, *args, **kwargs)
global method = undefined
app = <sage.repl.interpreter.SageTerminalApp object at 0x7f6ab0607050>
args = ()
kwargs = {}
89 except (TraitError, ArgumentError) as e:
90 app.log.fatal(“Bad config encountered during initialization: %s”, e)
91 app.log.debug(“Config at the time: %s”, app.config)
92 app.exit(1)
93
94 return inner
95
96 class ApplicationError(Exception):
97 pass
98
99
100 class LevelFormatter(logging.Formatter):
101 “”"Formatter with additional highlevel record
102
103 This field is empty if log level is less than highlevel_limit,

/srv/conda/envs/notebook/lib/python3.7/site-packages/IPython/terminal/ipapp.py in initialize(self=<sage.repl.interpreter.SageTerminalApp object>, argv=None)
304
305 return super(TerminalIPythonApp, self).parse_command_line(argv)
306
307 @catch_config_error
308 def initialize(self, argv=None):
309 “”“Do actions after construct, but before starting the app.”“”
310 super(TerminalIPythonApp, self).initialize(argv)
311 if self.subapp is not None:
312 # don’t bother initializing further, starting subapp
313 return
314 # print self.extra_args
315 if self.extra_args and not self.something_to_run:
316 self.file_to_run = self.extra_args[0]
317 self.init_path()
318 # create the shell
→ 319 self.init_shell()
self.init_shell = <bound method SageTerminalApp.init_shell of <sage.repl.interpreter.SageTerminalApp object at 0x7f6ab0607050>>
320 # and draw the banner
321 self.init_banner()
322 # Now a variety of things that happen after the banner is printed.
323 self.init_gui_pylab()
324 self.init_extensions()
325 self.init_code()
326
327 def init_shell(self):
328 “”“initialize the InteractiveShell instance”“”
329 # Create an InteractiveShell instance.
330 # shell.display_banner should always be False for the terminal
331 # based app, because we call shell.show_banner() by hand below
332 # so the banner shows before all extension loading stuff.
333 self.shell = self.interactive_shell_class.instance(parent=self,
334 profile_dir=self.profile_dir,

/srv/conda/envs/notebook/lib/python3.7/site-packages/sage/repl/interpreter.py in init_shell(self=<sage.repl.interpreter.SageTerminalApp object>)
776 self.shell.has_sage_extensions = SAGE_EXTENSION in self.extensions
777
778 # Load the %lprun extension if available
779 try:
780 import line_profiler
781 except ImportError:
782 pass
783 else:
784 self.extensions.append(‘line_profiler’)
785
786 if self.shell.has_sage_extensions:
787 self.extensions.remove(SAGE_EXTENSION)
788
789 # load sage extension here to get a crash if
790 # something is wrong with the sage library
→ 791 self.shell.extension_manager.load_extension(SAGE_EXTENSION)
self.shell.extension_manager.load_extension = <bound method ExtensionManager.load_extension of <IPython.core.extensions.ExtensionManager object at 0x7f6aac3ca410>>
global SAGE_EXTENSION = ‘sage’
792
793

/srv/conda/envs/notebook/lib/python3.7/site-packages/IPython/core/extensions.py in load_extension(self=<IPython.core.extensions.ExtensionManager object>, module_str=‘sage’)
72 if module_str in self.loaded:
73 return “already loaded”
74
75 from IPython.utils.syspathcontext import prepended_to_syspath
76
77 with self.shell.builtin_trap:
78 if module_str not in sys.modules:
79 with prepended_to_syspath(self.ipython_extension_dir):
80 mod = import_module(module_str)
81 if mod.file.startswith(self.ipython_extension_dir):
82 print(("Loading extensions from {dir} is deprecated. "
83 "We recommend managing extensions like any "
84 “other Python packages, in site-packages.”).format(
85 dir=compress_user(self.ipython_extension_dir)))
86 mod = sys.modules[module_str]
—> 87 if self._call_load_ipython_extension(mod):
self._call_load_ipython_extension = <bound method ExtensionManager._call_load_ipython_extension of <IPython.core.extensions.ExtensionManager object at 0x7f6aac3ca410>>
mod = <module ‘sage’ from ‘/srv/conda/envs/notebook/lib/python3.7/site-packages/sage/init.py’>
88 self.loaded.add(module_str)
89 else:
90 return “no load function”
91
92 def unload_extension(self, module_str):
93 “”“Unload an IPython extension by its module name.
94
95 This function looks up the extension’s name in sys.modules and
96 simply calls mod.unload_ipython_extension(self).
97
98 Returns the string “no unload function” if the extension doesn’t define
99 a function to unload itself, “not loaded” if the extension isn’t loaded,
100 otherwise None.
101 “””
102 if module_str not in self.loaded:

/srv/conda/envs/notebook/lib/python3.7/site-packages/IPython/core/extensions.py in _call_load_ipython_extension(self=<IPython.core.extensions.ExtensionManager object>, mod=<module ‘sage’ from ‘/srv/conda/envs/notebook/lib/python3.7/site-packages/sage/init.py’>)
119 “”"
120 from IPython.utils.syspathcontext import prepended_to_syspath
121
122 if (module_str in self.loaded) and (module_str in sys.modules):
123 self.unload_extension(module_str)
124 mod = sys.modules[module_str]
125 with prepended_to_syspath(self.ipython_extension_dir):
126 reload(mod)
127 if self._call_load_ipython_extension(mod):
128 self.loaded.add(module_str)
129 else:
130 self.load_extension(module_str)
131
132 def _call_load_ipython_extension(self, mod):
133 if hasattr(mod, ‘load_ipython_extension’):
→ 134 mod.load_ipython_extension(self.shell)
mod.load_ipython_extension = <function load_ipython_extension at 0x7f6ab057ff80>
self.shell = <sage.repl.interpreter.SageTerminalInteractiveShell object at 0x7f6aaed0ab50>
135 return True
136
137 def _call_unload_ipython_extension(self, mod):
138 if hasattr(mod, ‘unload_ipython_extension’):
139 mod.unload_ipython_extension(self.shell)
140 return True
141
142 @undoc
143 def install_extension(self, url, filename=None):
144 “”"
145 Deprecated.
146 “”"
147 # Ensure the extension directory exists
148 raise DeprecationWarning(
149 ‘install_extension and the install_ext magic have been deprecated since IPython 4.0’

/srv/conda/envs/notebook/lib/python3.7/site-packages/sage/init.py in load_ipython_extension(*args=(<sage.repl.interpreter.SageTerminalInteractiveShell object>,))
1 all = [‘all’]
2
3 # Set sage.version to the current version number. This is analogous
4 # to many other Python packages.
5 from sage.version import version as version
6
7 import sys
8 # Make sure that the correct zlib library is loaded. This is needed
9 # to prevent the system zlib to be loaded instead of the Sage one.
10 # See #23122 (Wrong zlib library might be loaded) – Sage
11 import zlib
12
13 # IPython calls this when starting up
14 def load_ipython_extension(*args):
15 import sage.repl.ipython_extension
—> 16 sage.repl.ipython_extension.load_ipython_extension(*args)
sage.repl.ipython_extension.load_ipython_extension = <function load_ipython_extension at 0x7f6aac15cd40>
args = (<sage.repl.interpreter.SageTerminalInteractiveShell object at 0x7f6aaed0ab50>,)
17
18
19 # Monkey-patch inspect.isfunction() to support Cython functions.
20 def isfunction(obj):
21 “”"
22 Check whether something is a function.
23
24 We assume that anything which has a genuine __code__
25 attribute (not using __getattr__ overrides) is a function.
26 This is meant to support Cython functions.
27
28 EXAMPLES::
29
30 sage: from inspect import isfunction
31 sage: def f(): pass

/srv/conda/envs/notebook/lib/python3.7/site-packages/sage/repl/ipython_extension.py in wrapper(*args=(<sage.repl.interpreter.SageTerminalInteractiveShell object>,), **kwargs={})
548 …: if work:
549 …: return ‘foo worked’
550 …: raise RuntimeError(“foo didn’t work”)
551 sage: foo(False)
552 Traceback (most recent call last):
553 …
554 RuntimeError: foo didn’t work
555 sage: foo(True)
556 ‘foo worked’
557 sage: foo(False)
558 sage: foo(True)
559 “”"
560 @wraps(func)
561 def wrapper(*args, **kwargs):
562 if not wrapper.has_run:
→ 563 result = func(*args, **kwargs)
result = undefined
global func = undefined
args = (<sage.repl.interpreter.SageTerminalInteractiveShell object at 0x7f6aaed0ab50>,)
kwargs = {}
564 wrapper.has_run = True
565 return result
566 wrapper.has_run = False
567 return wrapper
568
569
570 @run_once
571 def load_ipython_extension(ip):
572 “”"
573 Load the extension in IPython.
574 “”"
575 # this modifies ip
576 SageCustomizations(shell=ip)

/srv/conda/envs/notebook/lib/python3.7/site-packages/sage/repl/ipython_extension.py in load_ipython_extension(ip=<sage.repl.interpreter.SageTerminalInteractiveShell object>)
561 def wrapper(*args, **kwargs):
562 if not wrapper.has_run:
563 result = func(*args, **kwargs)
564 wrapper.has_run = True
565 return result
566 wrapper.has_run = False
567 return wrapper
568
569
570 @run_once
571 def load_ipython_extension(ip):
572 “”"
573 Load the extension in IPython.
574 “”"
575 # this modifies ip
→ 576 SageCustomizations(shell=ip)
global SageCustomizations = <class ‘sage.repl.ipython_extension.SageCustomizations’>
global shell = undefined
ip = <sage.repl.interpreter.SageTerminalInteractiveShell object at 0x7f6aaed0ab50>

/srv/conda/envs/notebook/lib/python3.7/site-packages/sage/repl/ipython_extension.py in init(self=<sage.repl.ipython_extension.SageCustomizations object>, shell=<sage.repl.interpreter.SageTerminalInteractiveShell object>)
420 def init(self, shell=None):
421 “”"
422 Initialize the Sage plugin.
423 “”"
424 self.shell = shell
425
426 self.auto_magics = SageMagics(shell)
427 self.shell.register_magics(self.auto_magics)
428
429 import sage.misc.edit_module as edit_module
430 self.shell.set_hook(‘editor’, edit_module.edit_devel)
431
432 self.init_inspector()
433 self.init_line_transforms()
434
→ 435 import sage.all # until sage’s import hell is fixed
sage.all = undefined
436
437 self.shell.verbose_quit = True
438 self.set_quit_hook()
439
440 self.register_interface_magics()
441
442 if SAGE_IMPORTALL == ‘yes’:
443 self.init_environment()
444
445 def register_interface_magics(self):
446 “”"
447 Register magics for each of the Sage interfaces
448 “”"
449 from sage.repl.interface_magic import InterfaceMagic
450 InterfaceMagic.register_all(self.shell)

/srv/conda/envs/notebook/lib/python3.7/site-packages/sage/all.py in
112
113 from sage.env import SAGE_ROOT, SAGE_SRC, SAGE_DOC_SRC, SAGE_LOCAL, DOT_SAGE, SAGE_ENV
114
115
116 ###################################################################
117
118 # This import also sets up the interrupt handler
119 from cysignals.signals import (AlarmInterrupt, SignalError,
120 sig_on_reset as sig_on_count)
121
122 from time import sleep
123 from functools import reduce # in order to keep reduce in python3
124
125 import sage.misc.lazy_import
126
→ 127 from sage.misc.all import * # takes a while
global sage.misc.all = undefined
128 from sage.typeset.all import *
129 from sage.repl.all import *
130
131 from sage.misc.sh import sh
132
133 from sage.libs.all import *
134 from sage.data_structures.all import *
135 from sage.doctest.all import *
136
137 from sage.structure.all import *
138 from sage.rings.all import *
139 from sage.arith.all import *
140 from sage.matrix.all import *
141
142 from sage.symbolic.all import *

/srv/conda/envs/notebook/lib/python3.7/site-packages/sage/misc/all.py in
75
76 from .defaults import (set_default_variable_name,
77 series_precision, set_series_precision)
78
79 from .sage_eval import sage_eval, sageobj
80
81 from .sage_input import sage_input
82
83 lazy_import(“sage.misc.cython”, [“cython_lambda”, “cython_create_local_so”])
84 lazy_import(“sage.misc.cython”, “cython_compile”, “cython”)
85
86 from .persist import save, load, dumps, loads, db, db_save
87
88 from .func_persist import func_persist
89
—> 90 from .functional import (additive_order,
global functional = undefined
global additive_order = undefined
global base_ring = undefined
global base_field = undefined
global basis = undefined
global category = undefined
global charpoly = undefined
global characteristic_polynomial = undefined
global coerce = undefined
global cyclotomic_polynomial = undefined
global decomposition = undefined
global denominator = undefined
global det = undefined
global dimension = undefined
global dim = undefined
global discriminant = undefined
global disc = undefined
global eta = undefined
global fcp = undefined
global gen = undefined
global gens = undefined
global hecke_operator = undefined
global image = undefined
global integral = undefined
global integrate = undefined
global integral_closure = undefined
global interval = undefined
global xinterval = undefined
global is_commutative = undefined
global is_even = undefined
global is_integrally_closed = undefined
global is_field = undefined
global is_odd = undefined
global kernel = undefined
global krull_dimension = undefined
global lift = undefined
global log = undefined
global log_b = undefined
global minimal_polynomial = undefined
global minpoly = undefined
global multiplicative_order = undefined
global ngens = undefined
global norm = undefined
global numerator = undefined
global numerical_approx = undefined
global n = undefined
global N = undefined
global objgens = undefined
global objgen = undefined
global order = undefined
global rank = undefined
global regulator = undefined
global round = undefined
global quotient = undefined
global quo = undefined
global isqrt = undefined
global squarefree_part = undefined
global symbolic_sum = undefined
global sum = undefined
global symbolic_prod = undefined
global product = undefined
global transpose = undefined
91 base_ring,
92 base_field,
93 basis,
94 category,
95 charpoly,
96 characteristic_polynomial,
97 coerce,
98 cyclotomic_polynomial,
99 decomposition,
100 denominator,
101 det,
102 dimension,
103 dim,
104 discriminant,
105 disc,

/srv/conda/envs/notebook/lib/python3.7/site-packages/sage/misc/functional.py in
11
12 - David Joyner (2005-12-20): More Examples
13 “”"
14 #*****************************************************************************
15 # Copyright (C) 2004 William Stein wstein@gmail.com
16 #
17 # This program is free software: you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation, either version 2 of the License, or
20 # (at your option) any later version.
21 # Licenses - GNU Project - Free Software Foundation
22 #*****************************************************************************
23 from future import absolute_import
24 import builtins
25
—> 26 from sage.rings.complex_double import CDF
global sage.rings.complex_double = undefined
global CDF = undefined
27 from sage.rings.real_double import RDF, RealDoubleElement
28 from sage.rings.integer_ring import ZZ
29 from sage.rings.integer import Integer
30 from sage.misc.superseded import deprecation
31
32 ##############################################################################
33 # There are many functions on elements of a ring, which mathematicians
34 # usually write f(x), e.g., it is weird to write x.log() and natural
35 # to write log(x). The functions below allow for the more familiar syntax.
36 ##############################################################################
37
38
39 def additive_order(x):
40 “”"
41 Return the additive order of x.

ImportError: /srv/conda/envs/notebook/lib/python3.7/site-packages/sage/rings/…/…/…/…/libgsl.so.25: undefined symbol: cblas_ctrmv


History of session input:
*** Last line of input (may not be in above history):

Seems related to this? But I don’t see a good solution there.

I tried this trick with no luck.

Attempted to try this idea; however, I don’t know if I did it right. No luck so far.

Now sage-bindr-env uses conda-forge and it works.

1 Like