Jupyter notebook Jupyter笔记本导出失败,出现“0”;nbconvert失败:Inkscape svg到pdf转换失败”;
当我尝试将Jupyter笔记本导出为pdf格式时,我收到以下错误<代码>nbconvert失败:Inkscape svg到pdf转换失败。导致错误的原因是什么?发生错误的原因是未安装导出到pdf软件。使用以下命令安装缺少的软件。显示的命令是针对debian发行版(如Ubuntu)的Jupyter notebook Jupyter笔记本导出失败,出现“0”;nbconvert失败:Inkscape svg到pdf转换失败”;,jupyter-notebook,jupyter-lab,tex,inkscape,export-to-pdf,Jupyter Notebook,Jupyter Lab,Tex,Inkscape,Export To Pdf,当我尝试将Jupyter笔记本导出为pdf格式时,我收到以下错误nbconvert失败:Inkscape svg到pdf转换失败。导致错误的原因是什么?发生错误的原因是未安装导出到pdf软件。使用以下命令安装缺少的软件。显示的命令是针对debian发行版(如Ubuntu)的 sudo apt update && sudo apt upgrade sudo apt install inkscape pandoc texlive-xetex texlive-fonts-recomme
sudo apt update && sudo apt upgrade
sudo apt install inkscape pandoc texlive-xetex texlive-fonts-recommended texlive-generic-recommended
在MacOSX和Anaconda发行版上,我也面临同样的问题。我发现问题出在
/Applications/anaconda3/lib/python3.7/site packages/nbconvert/preprocessors/svg2pdf.py
文件中
据
在这个文件中,有一些行(我已经注释掉了)已经过时,需要替换为以下内容
class SVG2PDFPreprocessor(ConvertFiguresPreprocessor):
"""
Converts all of the outputs in a notebook from SVG to PDF.
"""
@default('from_format')
def _from_format_default(self):
return 'image/svg+xml'
@default('to_format')
def _to_format_default(self):
return 'application/pdf'
command = Unicode(
help="""The command to use for converting SVG to PDF
This string is a template, which will be formatted with the keys
to_filename and from_filename.
The conversion call must read the SVG from {from_filename},
and write a PDF to {to_filename}.
""").tag(config=True)
# @default('command')
# def _command_default(self):
# return self.inkscape + \
# ' --without-gui --export-pdf="{to_filename}" "{from_filename}"'
@default('command')
def _command_default(self):
return self.inkscape + \
' --export-type="pdf" "{to_filename}" "{from_filename}"'
另外,请确保已安装Inkscape:
- 我已经下载并安装了dmg
- 我还对二进制文件进行了符号链接:
sudo ln-s/Applications/Inkscape.app/Contents/MacOS/Inkscape/usr/local/bin
raoul@mbp-de-raoul ~ % export PATH=/Applications/anaconda3/bin:$PATH
raoul@mbp-de-raoul ~ % jupyter --version
jupyter core : 4.6.1
jupyter-notebook : 6.0.3
qtconsole : 4.6.0
ipython : 7.12.0
ipykernel : 5.1.4
jupyter client : 5.3.4
jupyter lab : 1.2.6
nbconvert : 5.6.1
ipywidgets : 7.5.1
nbformat : 5.0.4
traitlets : 4.3.3
- 然后重新启动服务器
现在导出文件>下载为>pdf正在工作。这是一个目前尚未解决的问题,看起来: 但对我来说,安装nbconvert 6.0.0版本是可行的。在该版本中,@Raoul提到的代码已被修改:
pip install nbconvert==6.0.0
您还需要安装Inkscape,并确保可以从终端打开Inkscape。在MacOS中,我必须这样做:
ln -s /Applications/Inkscape.app/Contents/MacOS/inkscape \
/usr/local/bin/inkscape
我认为可执行文件的具体位置取决于您的inkscape版本。但是如果你有最新的版本,它应该是相同的。基本上,在终端中键入
inkscape
应该会打开inkscape。这就是您想要的。命令pip install nbconvert==6.0.0
解决了我的问题。谢谢