pythonipythonoctaveoct2py

Oct2PyError occurs in ipython when octavemagic is used


I want to use octave functionality from ipython. Therefore,I installed oct2py module by pip command. (To be precise, I'm using ipython3 and pip3 command)

The installation itself was done successfully. According to this web page, I tried following commands in ipython terminal mode.

In [1]: %load_ext octavemagic 

--> %octave becomes available apparently.

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

--> ipython said following error message.

How can I use octavemagic without Oct2PyError? Any help would be appreciated. Thanks in advance.

------------------------------------------------------------------    ---------
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'

Environment and Software Version


Solution

  • I find the solution from this page. I'm sorry for not knowing this.

    Following command works fine.

    In [1]: %load_ext oct2py.ipython
    
    In [2]: x = %octave [1 2; 3 4];