调用Mathematica时,Sage挂起

时间:2015-06-02 02:52:08

标签: python wolfram-mathematica sage

我最近在我的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?

1 个答案:

答案 0 :(得分:3)

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