0

I am trying to draft a MATLAB/Octave tutorial on Google Colab, and was hoping to use magic commands %octave and %%octave to write most of the cells. However, when I tried to setup the environment using the below commands

!apt-get install octave
!pip install oct2py
%load_ext oct2py.ipython

I got an error AttributeError: module 'oct2py' has no attribute 'octave' for the %load_ext command above, here is the full error log:

AttributeError                            Traceback (most recent call last)
<ipython-input-3-0c05e6d2529c> in <cell line: 3>()
      1 get_ipython().system('apt-get install octave')
      2 get_ipython().system('pip install oct2py')
----> 3 get_ipython().run_line_magic('load_ext', 'oct2py.ipython')

7 frames
<decorator-gen-57> in load_ext(self, module_str)

/usr/local/lib/python3.9/dist-packages/oct2py/ipython/octavemagic.py in __init__(self, shell)
     70         """
     71         super().__init__(shell)
---> 72         self._oct = oct2py.octave
     73 
     74         # Allow display to be overridden for

AttributeError: module 'oct2py' has no attribute 'octave'

I am wondering if this is a known issue, and if there is any workaround.

FangQ
  • 1,444
  • 10
  • 18
  • 1
    Hmmm. I just ran it on colab and although it took like 5+ minutes to run, it did work. – Ori Yarden PhD Apr 24 '23 at 20:16
  • 1
    @OriYarden, you were absolutely right! I started a new notebook and reran the same commands, this time, it finished without error and both `%octave` and `%%octave` magic commands worked nicely! feel free to start an answer and I will accept it – FangQ Apr 25 '23 at 02:39

1 Answers1

0

As @OriYarden noted in a previous reply - the commands in fact worked fine. The previous issue I had may just be a glitch due to incomplete installation.

Again, these 3 commands do work (takes 4-5 min to complete) to make Google Colab to support Octave magic commands

!apt-get install octave
!pip install oct2py
%load_ext oct2py.ipython
FangQ
  • 1,444
  • 10
  • 18