问题
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:
(The Colab File Menu options don't do the necessary export, which is why I need
nbconvert
. Downloading to a local machine and runningnbconvert
is also not an option here.)The simplest attempt to link to the file directly (when authenticated)
!jupyter nbconvert 'https://colab.research.google.com/drive/2pexUcovcblu1Api0F0NezyhZyN2MEMWLhs5ujm?authuser=2
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.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:
Upload your
foo.ipynb
to your home directory on Colaboratory. (The home directory is/content/
)Run:
!jupyter nbconvert --to html /content/foo.ipynb
Download
foo.html
to your local machine.
来源:https://stackoverflow.com/questions/52084744/how-to-run-nbconvert-on-notebook-in-google-colaboratory