Jupyter notebook download as pdf

Jupyter notebook download as pdf

Download as pdf

  • jupyter notebook确实蛮好用的,写着方便(markdown写着很舒服),但众所周知ipynb这个文件格式(notebook的文件后缀名)跟html,docx,pdf等格式不同,它不是很通用,在某些时候还是有着不方便之处,所以就有了转换的需求。
    转换pdf错误
  • 但是问题来了,如果用原生的jupyter nobebook是不能够导出pdf格式的,如上所示。

###官方的提示传送门

  • 实际上这个错误官方给出了解决网址,即:https://nbconvert.readthedocs.io/en/latest/install.html#installing-tex
  • 我们可以点进去看一下,发现是提示我们安装nbconvert的,由于我用的是anaconda的环境所以命令是:
conda install nbconvert
  • 有一点比较奇怪,就是这段话:

If you’re new to Python, we recommend installing Anaconda, a Python distribution which includes nbconvert and the other Jupyter components.

  • 大体意思是在推荐Anaconda,而且说它包含了nbconvert,实际上我装的最新版Anaconda中nbconvert并不符合要求,或者根本就没有(没有求证过)
  • 接下来是一个important的提示:

To unlock nbconvert’s full capabilities requires Pandoc and TeX (specifically, XeLaTeX). These must be installed separately.

  • 说解锁nbconvert的全部功能需要Pandoc 和TeX ,这里就是说我们还需要上述两个组件,官方给出的命令是apt,是乌班图中的安装我用的是Centos云主机,所以改成yum即可,需要注意的是,无论是yum还是apt-get都需要root权限,所以需要加上sudo,如果以root登录则不用

pandoc安装

#ubuntu 中的安装
sudo apt-get install pandoc
#Centos中安装
sudo yum install pandoc

Tex安装

  • 有关于Tex每一种系统又不同版本,如Windows系列 是MikTex,Mac系列是MacTeX,对于Linux系列则是TexLive,这里官方给出了Ubuntu的Tex Live的安装命令,同样,改成Centos的即可
#Ubuntu安装
sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-generic-recommended
#Centos安装
sudo yum install texlive-xetex texlive-fonts-recommended texlive-generic-recommended

测试

  • 我们此时可以打开jupyter notebook 来下载一下,download as pdf
    测试失败

  • 发现依旧是500 错误,这次的错误日志不一样,说是xelatex.fml找不到

关于这个问题的解释

  • 我们可以猜想是TeX Live安装出了问题(根据log中的提示)

  • 我在解决前曾经找过许多方法,发现这个错误是由于没有Latex的缘故,但是我当我安装完Latex之后,又出现新的错误,自此我认为我的Tex 包缺失严重,所以决定安装完整版的Tex Live。

  • 安装Latex之后的错误log

nbconvert failed: PDF creating failed, captured latex output:
This is XeTeX, Version 3.1415926-2.5-0.9999.3 (TeX Live 2013)
 restricted \write18 enabled.
entering extended mode
(./notebook.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, lo
aded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size11.clo
kpathsea: Running mktextfm cmr10
/usr/share/texlive/texmf/web2c/mktexnam: Could not map source abbreviation  for cmr10.
/usr/share/texlive/texmf/web2c/mktexnam: Need to update ?
mktextfm: Running mf \mode:=ljfour; mag:=1; nonstopmode; input cmr10
/usr/bin/mktextfm: line 96: mf: command not found
grep: cmr10.log: No such file or directory
mktextfm: `mf \mode:=ljfour; mag:=1; nonstopmode; input cmr10' failed to make cmr10.tfm.
kpathsea: Appending font creation commands to missfont.log.

! Font OT1/cmr/m/n/10.95=cmr10 at 10.95pt not loadable: Metric (TFM) file or in
stalled font not found.
<to be read again> 
                   relax 
l.64 \normalsize
                
? 
! Emergency stop.
<to be read again> 
                   relax 
l.64 \normalsize
                
No pages of output.
Transcript written on notebook.log.
  • Could not map source abbreviation for cmr10,根据提示像是版本过低(事实上自动安装的texlive版本确实比较老),需要更新。
  • 这也证实了我的猜想是正确的——装了整个Tex Live 2019(大约3个G)之后第一次解决问题,下一篇将讲述Tex Live的安装。

##### Centos7 安装Tex Live传送门


PS

实际上任何浏览器都可以生成pdf——右键打印,最终会下载一个pdf,只不过没有编译出来的pdf好看(个人认为)
打印下来的是一个pdf

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

椰子奶糖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值