Jupyter Notebook Conversion
文章目录
遇到的情形
分析的代码已经调试好,但分析的时间较长;
后端启动jupyter notebook后,奈何网络不稳定,notebook经常掉线,跑到一半的程序就断掉了;
服务器其他人的jupyter notebook的端口如果和我的一样,别人启动jupyter notebook后,我正在用的端口就会往后变。
于是我就想,能否在终端直接运行.ipynb文件,这样我就可以加nohup命令了,或者把ipynb的代码转成python,我nohup运行python也行。
基于以上情况,我google到了nbconvert。
nbconvert
nbconvert的github地址:https://github.com/jupyter/nbconvert
jupyter nbconvert通过模版引擎jinja将ipynb文件转成其他格式的文件,包括
- HTML
- LaTeX
- Reveal JS
- Markdown (md)
- ReStructured Text (rst)
- executable script
此外nbconvert还有另外一个功能就是通过–execute选项在终端执行ipynb文件
安装nbconvert
|
|
ipynb格式转换
|
|
上面是格式转换,在转换的过程中,比如转pdf、latex的时候,可能还需要额外的包,比如pandoc等,还需要额外安装。可以参考https://nbconvert.readthedocs.io/en/latest/index.html
jupyter nbconvert还有个功能就是执行ipynb格式的文件,如下
|
|
假设我想把通过运行jupyter nbconvert执行ipynb文件的过程更简单点,可以通过在.profile里面设置命令的别名
|
|
参考
https://stackoverflow.com/questions/35545402/how-to-run-an-ipynb-jupyter-notebook-from-terminal
Github: https://github.com/jupyter/nbconvert
Document: https://nbconvert.readthedocs.io/en/latest/index.html
####################################################################
#版权所有 转载请告知 版权归作者所有 如有侵权 一经发现 必将追究其法律责任
#Author: Jason
#####################################################################
文章作者 zzx
上次更新 2023-03-29