当使用octavemagic时,在ipython中会出现Oct2PyError

时间:2014-10-04 01:48:55

标签: python ipython octave oct2py

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

安装本身已成功完成。 根据{{​​3}},我在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位)

  • python:3.4.0

  • ipython:2.3.0

  • oct2py:2.4.0

  • numpy:1.9.0

  • octave:3.8.1

1 个答案:

答案 0 :(得分:1)

我从this page找到解决方案。 对不起,我很抱歉。

以下命令正常工作。

In [1]: %load_ext oct2py.ipython

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