简体   繁体   English

在 Google Colab 中将 ipynb 笔记本转换为 HTML

[英]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 选项?

"

Method using only Google Colab仅使用 Google Colab 的方法

  1. Download your .ipynb file下载您的 .ipynb 文件

You can actually do it using only Google Colab.您实际上可以仅使用 Google Colab 来完成。 File -> Download .ipynb File -> Download .ipynb


  1. Reupload it so Colab can see it重新上传它以便 Colab 可以看到它

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文件。


  1. Get your file's path获取文件路径

then obtain its path (you might need to hit the Refresh button before your file shows up):然后获取其路径(您可能需要在文件显示之前点击Refresh按钮):

在此处输入图片说明


  1. Conversion using %%shell使用 %%shell 转换

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


  1. Your file is ready您的文件已准备就绪

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 Google Colab 笔记本转换为 PDF/HTML? - Convert Google Colab notebook to PDF / HTML? Jupyter (IPython) 笔记本:将 HTML 笔记本转换为 ipynb - Jupyter (IPython) notebook: Convert an HTML notebook to ipynb 如何通过 Google Colab notebook (.ipynb) 访问 Google Drive 上的文件? - How to access files on Google Drive via Google Colab notebook (.ipynb)? 使用 Google Colab 运行时查找 python_notebook.ipynb 的路径 - Find path of python_notebook.ipynb when running it with Google Colab 将保存为 .HTML 文件的 jupyter notebook 转换回 .IPYNB - convert jupyter notebook saved as .HTML file back into .IPYNB 我可以将在 Google Colab 的 Tensorflow 上创建的“.py”或“.ipynb”模型/文件转换为 coreML 模型/文件吗? - Can I convert a “.py” or “.ipynb” model/file created on Google Colab's Tensorflow to a coreML model/ file? 在 google colab 上导入自己的 ipynb 文件 - import its own ipynb files on google colab 在 Google Colab 中创建 Multiple.ipynb 笔记本 - Creating Multiple .ipynb Notebooks in Google Colab 如何将 Flutter 应用程序与 ipynb/colab 笔记本集成? - How do I integrate a Flutter application with ipynb/colab notebook? 将 JSON IPython 笔记本 (.ipynb) 转换为 .py 文件 - Convert JSON IPython notebook (.ipynb) to .py file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM