我们用jupyter notebook最后保存的文件是.ipynb格式,但可能要转换成其它格式来应用到其它场景。
比如要改成.py文件用命令行的方式来执行;markdown格式可以把自己的工作上传到博客或一些云笔记上;或都是html格式,可以用浏览器来查看;还有是转成latex格式更好处理复杂的格式,另外从latex还可以转换成pdf或word的.docx。
jupyter 自带转换工具,在安装完成之后,可以通过以下命令来查看它的使用方法:
jupyter nbconvert --help
将会返回大部分的使用说明以及参数作用,下面我们列一些常用的:
1、ipynb转py文本
jupyter nbconvert --to python yourfile.ipynb
2、ipynb转markdown
jupyter nbconvert --to python yourfile.ipynb
3、ipynb转html
jupyter nbconvert --to html yourfile.ipynb
4、ipynb转latex
jupyter nbconvert --to latex yourfile.ipynb
5、ipynb转pdf
jupyter nbconvert --to pdf yourfile.ipynb
在执行4,5项的时候会出一些缺包的情况,我执行4遇到的是没有装pandoc,
安装参照:https://pandoc.org/installing.html#linux,下载了tar包并解压到相关位置
执行5的时候还缺少xelatex,安装参照:https://www.jianshu.com/p/d185aad1f915
最后这些转换都成功了。