[英]Convert ipynb notebook to HTML in Google Colab
I have a Google Colaboratory Notebook for Data Analysis that I want to output as a HTML file as currently not everything loads within the Colab environment such as large Folium Heatmaps.我有一个用于数据分析的 Google Colaboratory Notebook,我想将其输出为 HTML 文件,因为目前并非所有内容都加载到 Colab 环境中,例如大型 Folium 热图。 Is it possible to export the notebook as a html file as opposed to the ipynb and py options?是否可以将笔记本导出为 html 文件,而不是 ipynb 和 py 选项?
"You can actually do it using only Google Colab.您实际上可以仅使用 Google Colab 来完成。 File
-> Download .ipynb
File
-> Download .ipynb
Click on the Files
icon on the far left:单击最左侧的Files
图标:
Then Upload to session storage
:然后Upload to session storage
:
Select & upload your .ipynb
file you just downloaded.选择并上传您刚刚下载的.ipynb
文件。
then obtain its path (you might need to hit the Refresh
button before your file shows up):然后获取其路径(您可能需要在文件显示之前点击Refresh
按钮):
Then, just as in Julio 's answer , execute in a Colab cell:然后,就像在Julio的回答中一样,在 Colab 单元中执行:
%%shell
jupyter nbconvert --to html /PATH/TO/YOUR/NOTEBOOKFILE.ipynb
The %%shell
lets the interpreter know that the following script is interpreted as shell. %%shell
让解释器知道以下脚本被解释为 shell。 Don't write anything before %%shell
, use a distinct cell for this.不要在%%shell
之前写任何东西,为此使用一个不同的单元格。
The form of /PATH/TO/YOUR/NOTEBOOKFILE.ipynb
will be something like /content/lightaberration3.ipynb
. /PATH/TO/YOUR/NOTEBOOKFILE.ipynb
的形式类似于/content/lightaberration3.ipynb
。
Might need to click Refresh
again, but your notebook.html
will appear in the files, so you can download it:可能需要再次单击Refresh
,但您的notebook.html
将出现在文件中,因此您可以下载它:
The great thing about this is that nothing python-related has to be installed on your computer, not conda , not pip , only a browser.这样做的好处是您的计算机上不需要安装任何与 python 相关的东西,不需要conda ,不需要pip ,只需一个浏览器。
Google Colab doesn't currently have such a feature as a built-in. Google Colab 目前没有内置功能。
Your best route is to first download it through File > Download .ipynb
and then use the standard tool for Jupyter Notebook conversion, nbconvert
:最好的方法是首先通过File > Download .ipynb
下载它,然后使用 Jupyter Notebook 转换的标准工具nbconvert
:
jupyter nbconvert --to html notebook.ipynb
If you use an Anaconda Python distribution, nbconvert
is most likely already installed.如果您使用 Anaconda Python 发行版,则很可能已经安装了nbconvert
。 If not, refer to what is described in their install instructions to be able to convert:如果没有,请参阅他们的安装说明中描述的内容以进行转换:
pip install nbconvert
# OR
conda install nbconvert
to continue with "Method using only Google Colab" " %%shell jupyter nbconvert --to html /PATH/TO/YOUR/NOTEBOOKFILE.ipynb" - as given继续“仅使用 Google Colab 的方法”“%%shell jupyter nbconvert --to html /PATH/TO/YOUR/NOTEBOOKFILE.ipynb” - 如给定
the following worked for me - type the following in Google Colab !pip install nbconvert以下内容对我有用 - 在 Google Colab 中输入以下内容 !pip install nbconvert
%shell jupyter nbconvert --to html /content/testfile.ipynb %shell jupyter nbconvert --to html /content/testfile.ipynb
I tried the approach above but couldn't get it to work - for small jobs I log onto https:\/\/jupyter.org\/try<\/a> , upload the downloaded ipynb file from Google Colab and then I opened the file, from here you will have the functionality in jupyter.org to download as html or whatever other format you require.我尝试了上述方法,但无法正常工作 - 对于小型工作,我登录https:\/\/jupyter.org\/try<\/a> ,从 Google Colab 上传下载的 ipynb 文件,然后打开文件,从这里你将拥有jupyter.org 中以 html 或您需要的任何其他格式下载的功能。 It took the pain out of trying to get it to work.它消除了试图让它工作的痛苦。
"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.