muskrat
muskrat

Reputation: 1549

How to run nbconvert on notebook in google colaboratory

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).

Upvotes: 5

Views: 7850

Answers (1)

Tomoyuki
Tomoyuki

Reputation: 41

  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.

Upvotes: 4

Related Questions