如何在Google colaboratory中的笔记本上运行nbconvert [英] How to run nbconvert on notebook in google colaboratory

查看:158
本文介绍了如何在Google colaboratory中的笔记本上运行nbconvert的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的jupyter笔记本,例如foo.ipynb.我只希望以通常的方式运行nbconvert:在我的本地计算机上,我将在笔记本本身中执行!jupyter nbconvert foo.ipynb,或者在shell中执行jupyter notebook foo.ipynb.在Google合作实验室上,此操作无效.当然,这是因为foo.ipynb不在驱动器上本地运行,但是在这种情况下,无法连接Drive和Colab的常用方法. 问题:有可能在Colab笔记本中(如!jupyter nbconvert foo.ipynb中一样)在Colab笔记本上运行nbconvert,如果可以,怎么办?,我尝试过:

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. ("Colab文件菜单"选项未执行必要的导出,这就是为什么我需要nbconvert的原因.在这里也不选择下载到本地计算机并运行nbconvert.)

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

最简单的尝试直接链接到文件(通过身份验证时)!jupyter nbconvert 'https://colab.research.google.com/drive/2pexUcovcblu1Api0F0NezyhZyN2MEMWLhs5ujm?authuser=2

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

此SO帖子: Google Colab :如何从我的Google云端硬盘读取数据? 但是,再次没有运气,因为它似乎无法找到文件,并且nbconvert只需要一个文件名.

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.

SO帖子中建议的其他方法,包括:将数据导入Google Colaboratory

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?

如何在笔记本中的colab笔记本上完成nbconvert?我可以验证nbconvert在colab上是否可用;它只是无法通过上述任何一种方法找到文件(据我所能).

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. 将您的foo.ipynb上载到Colaboratory上的主目录中. (主目录为/content/)

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

运行: !jupyter nbconvert --to html /content/foo.ipynb

下载foo.html到本地计算机.

这篇关于如何在Google colaboratory中的笔记本上运行nbconvert的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆