How to run nbconvert on notebook in google colaboratory

断了今生、忘了曾经 提交于 2021-01-21 05:19:42

问题


I have a simple jupyter notebook, say foo.ipynb. I wish simply to run nbconvert in the usual way: on my local machine I would execute !jupyter nbconvert foo.ipynb in the notebook itself, or jupyter notebook foo.ipynb in a shell. On Google Colaboratory, this does not work. Of course this is because foo.ipynb is not running locally on the drive, but the usual methods to connect Drive and Colab are not working in this case. Question: is running nbconvert on a Colab notebook possible from within a Colab notebook (as in !jupyter nbconvert foo.ipynb), and if so, how? I have tried:

  1. (The Colab File Menu options don't do the necessary export, which is why I need nbconvert. Downloading to a local machine and running nbconvert is also not an option here.)

  2. The simplest attempt to link to the file directly (when authenticated) !jupyter nbconvert 'https://colab.research.google.com/drive/2pexUcovcblu1Api0F0NezyhZyN2MEMWLhs5ujm?authuser=2

  3. This SO post: Google Colab: how to read data from my google drive? But again no luck, since it can’t seem to find the file and nbconvert only takes a filename.

  4. Other approaches suggested in SO posts, including: Is it possible to import my own modules into a google-colaboratory notebook? , Import data into Google Colaboratory , How to run a downloaded Jupyter notebook on Google Colaboratory?

How can I accomplish nbconvert on a colab notebook, within the notebook? I can verify that nbconvert is available on colab; it's just not able to find the file under any of the above approaches (so far as I have been able).


回答1:


  1. Upload your foo.ipynb to your home directory on Colaboratory. (The home directory is /content/)

  2. Run: !jupyter nbconvert --to html /content/foo.ipynb

  3. Download foo.html to your local machine.



来源:https://stackoverflow.com/questions/52084744/how-to-run-nbconvert-on-notebook-in-google-colaboratory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!