Sage 在调用 Mathematica 时挂起

Sage hangs when calling Mathematica

我最近在我的 Fedora 21 机器上安装了 Sage 6.3。我使用的是 6.3 版,它有点过时了,因为它是 yum 存储库中可用的最新版本。我还在同一台计算机上安装了 Mathematica,希望能够从 Sage 中调用它。

使用 math 命令的 Mathematica 终端界面可以工作,根据 this reference page 这应该是我所需要的。但是,当我告诉 Sage 从 Sage 命令行或笔记本使用 mathematica 时,Sage 挂起。这是我与终端交互的示例(回溯很糟糕,在 Sage 中经常出现这种情况):

sage: mathematica('hello world')
^CInterrupting Mathematica...
^C---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-1-9208bb19d841> in <module>()
----> 1 mathematica('hello world')

/usr/lib64/python2.7/site-packages/sage/interfaces/interface.pyc in __call__(self, x, name)
    197
    198         if isinstance(x, basestring):
--> 199             return cls(self, x, name=name)
    200         try:
    201             return self._coerce_from_special_method(x)

/usr/lib64/python2.7/site-packages/sage/interfaces/expect.pyc in __init__(self, parent, value, is_name, name)
   1310         else:
   1311             try:
-> 1312                 self._name = parent._create(value, name=name)
   1313             # Convert ValueError and RuntimeError to TypeError for
   1314             # coercion to work properly.

/usr/lib64/python2.7/site-packages/sage/interfaces/interface.pyc in _create(self, value, name)
    387     def _create(self, value, name=None):
    388         name = self._next_var_name() if name is None else name
--> 389         self.set(name, value)
    390         return name
    391

/usr/lib64/python2.7/site-packages/sage/interfaces/mathematica.pyc in set(self, var, value)
    508         cmd = '%s=%s;'%(var,value)
    509         #out = self.eval(cmd)
--> 510         out = self._eval_line(cmd, allow_use_file=True)
    511         if len(out) > 8:
    512             raise TypeError("Error executing code in Mathematica\nCODE:\n\t%s\nMathematica ERROR:\n\t%s"%(cmd, out))

/usr/lib64/python2.7/site-packages/sage/interfaces/mathematica.pyc in _eval_line(self, line, allow_use_file, wait_for_prompt, restart_if_needed)
    535     def _eval_line(self, line,  allow_use_file=True, wait_for_prompt=True, restart_if_needed=False):
    536         s = Expect._eval_line(self, line,
--> 537              allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt)
    538         return str(s).strip('\n')
    539

/usr/lib64/python2.7/site-packages/sage/interfaces/expect.pyc in _eval_line(self, line, allow_use_file, wait_for_prompt, restart_if_needed)
    890                     out = ''
    891         except KeyboardInterrupt:
--> 892             self._keyboard_interrupt()
    893             raise KeyboardInterrupt("Ctrl-c pressed while running %s"%self)
    894         if self._terminal_echo:

/usr/lib64/python2.7/site-packages/sage/interfaces/mathematica.pyc in _keyboard_interrupt(self)
    420         e = self._expect
    421         e.sendline(chr(3))  # send ctrl-c
--> 422         e.expect('Interrupt> ')
    423         e.sendline("a")  # a -- abort
    424         e.expect(self._prompt)

/usr/lib64/sagemath/site-packages/pexpect.pyc in expect(self, pattern, timeout, searchwindowsize)
    914         """
    915         compiled_pattern_list = self.compile_pattern_list(pattern)
--> 916         return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
    917
    918     def expect_list(self, pattern_list, timeout = -1, searchwindowsize = -1):

/usr/lib64/sagemath/site-packages/pexpect.pyc in expect_list(self, pattern_list, timeout, searchwindowsize)
    965                     raise TIMEOUT ('Timeout exceeded in expect_list().')
    966                 # Still have time left, so read more data
--> 967                 c = self.read_nonblocking (self.maxread, timeout)
    968                 incoming = incoming + c
    969                 if timeout is not None:

/usr/lib64/sagemath/site-packages/pexpect.pyc in read_nonblocking(self, size, timeout)
    546                 raise EOF ('End Of File (EOF) in read_nonblocking(). Pokey platform.')
    547
--> 548         r, w, e = select.select([self.child_fd], [], [], timeout)
    549         if not r:
    550             if not self.isalive():

/usr/lib64/python2.7/site-packages/sage/ext/c_lib.so in sage.ext.c_lib.sage_python_check_interrupt (build/cythonized/sage/ext/c_lib.c:1683)()

/usr/lib64/python2.7/site-packages/sage/ext/c_lib.so in sage.ext.c_lib.sig_raise_exception (build/cythonized/sage/ext/c_lib.c:769)()

KeyboardInterrupt:
sage:

Mathematica 自己的界面中的等效项工作得很好:

Mathematica 10.1.0 for Linux x86 (64-bit)
Copyright 1988-2015 Wolfram Research, Inc.

In[1]:= hello world

Out[1]= hello world

In[2]:=

我是不是做错了什么,或者这是 Sage 中的错误?手动下载和构建最新版本 (6.7) 是否可以解决问题?

编辑:

我正在使用 Mathematica 10.1.0。会不会是我的问题,即旧版本的 Sage 不知道如何处理新版本的 Mathematica?

根据Trac 16703,这个问题应该在最新的 Sage 中得到修复。我个人没有 Mathematica 的副本来测试它。