0

In google Colab, I cloned a github project. Then I executed some bash commands. There is a notebook folder inside this project containing several notebooks. Already, I converted them to python files and tried to run them using

!ipython3 file.py

It gives me some error on visual parts like:

nknownBackendTraceback (most recent call last)
/content/notebooks/ml.py in <module>()
     13 get_ipython().magic(u'reload_ext autoreload')
     14 get_ipython().magic(u'autoreload 2')
---> 15 get_ipython().magic(u'matplotlib inline')

I either must resolve this errors, or load and run the ipython notebook in Google Colab. Could I do that?

Ahmad
  • 8,811
  • 11
  • 76
  • 141

2 Answers2

0

This is possibly because the notebook contains magic commands(Like your traceback suggests), and a notebook containing magic commands will not convert to a usable script; the script will raise an error that get_ipython() is not defined, or there is an UnknownBackend, etc.

for fixing the errors for get_ipython().magic(u'reload_ext autoreload') and get_ipython().magic(u'autoreload 2'), look here.

About get_ipython().magic(u'matplotlib inline'), that one is still an open issue. You can find it on their official github here, where they do discuss a few potential solutions. This discusses a few potential solutions too.

Ayush
  • 1,510
  • 11
  • 27
  • myabe I don't need them... I just want to run the code in python format, then I might be able to remove some of them, not? – Ahmad Jun 26 '20 at 09:53
  • That's possible as well. You could experiment doing that, though for example, you may see some plots not getting plotted when you remove `%matplotlib inline` command. You could also work around this by calling for a different backend, but that choice of backend is then user dependent. (Perhaps local matplotlib default.) But yes, if you're only looking for some 'results' and don't care much about the GUI part, then do try stripping off the backend command. – Ayush Jun 26 '20 at 10:11
0

You can use %run instead

%run file.py

This should load the file and run as if it's in Colab itself.

korakot
  • 37,818
  • 16
  • 123
  • 144