0

我想使用 ipython 的 octave 功能。因此,我通过 pip 命令安装了 oct2py 模块。(准确地说,我使用的是 ipython3 和 pip3 命令)

安装本身已成功完成。根据这个网页,我在 ipython 终端模式下尝试了以下命令。

In [1]: %load_ext octavemagic 

--> %octave 显然变得可用。

In [2]: x = %octave [1 2; 3 4];x

--> ipython 说下面的错误信息。

如何在没有 Oct2PyError 的情况下使用 octavemagic?任何帮助,将不胜感激。提前致谢。

------------------------------------------------------------------    ---------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-d604e29afc22> in <module>()
----> 1 x = get_ipython().magic('octave [1 2; 3 4];')

/usr/local/lib/python3.4/dist-packages/IPython/core/interactiveshell.py in magic(self, arg_s)
   2203         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2204         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2205         return self.run_line_magic(magic_name, magic_arg_s)
   2206 
   2207     #-------------------------------------------------------------------------

/usr/local/lib/python3.4/dist-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line)
   2124                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2125             with self.builtin_trap:
-> 2126                 result = fn(*args,**kwargs)
   2127             return result
   2128 

/usr/local/lib/python3.4/dist-packages/IPython/extensions/octavemagic.py in octave(self, line, cell, local_ns)

/usr/local/lib/python3.4/dist-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    191     # but it's overkill for just that one bit of state.
    192     def magic_deco(arg):
--> 193         call = lambda f, *a, **k: f(*a, **k)
    194 
    195         if callable(arg):

/usr/local/lib/python3.4/dist-packages/IPython/extensions/octavemagic.py in octave(self, line, cell, local_ns)
    326             text_output = self._oct.run(code, verbose=False)
    327         except (oct2py.Oct2PyError) as exception:
--> 328             msg = exception.message
    329             msg = msg.split('# ___<end_pre_call>___ #')[1]
    330             msg = msg.split('# ___<start_post_call>___ #')[0]

AttributeError: 'Oct2PyError' object has no attribute 'message'

环境和软件版本

  • 操作系统:Ubuntu 14.04LTS(64 位)

  • 蟒蛇:3.4.0

  • ipython:2.3.0

  • oct2py:2.4.0

  • 麻木:1.9.0

  • 八度:3.8.1

4

1 回答 1

1

我从这个页面找到解决方案。我很抱歉不知道这一点。

以下命令工作正常。

In [1]: %load_ext oct2py.ipython

In [2]: x = %octave [1 2; 3 4];
于 2014-10-04T02:16:26.457 回答