4

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

muskrat
  • 1,519
  • 11
  • 18

1 Answers1

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

Tomoyuki
  • 41
  • 2
  • This works well although you need to install some things first if you want pdf output. Do this in a cell in Colab `!sudo apt-get update` `!sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-generic-recommended`. Then run this to convert `!jupyter nbconvert --to pdf /content/foo.ipynb` – Andrew Chisholm Jan 15 '21 at 20:39