当我尝试将Jupyter笔记本导出为PDF格式时,我收到以下错误信息:nbconvert失败:Inkscape SVG转PDF转换失败
。是什么导致了这个错误?
当我尝试将Jupyter笔记本导出为PDF格式时,我收到以下错误信息:nbconvert失败:Inkscape SVG转PDF转换失败
。是什么导致了这个错误?
目前似乎存在一个开放问题:https://github.com/jupyter/nbconvert/issues/1325
但对我来说,安装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,这就是你想要的。
sudo apt update && sudo apt upgrade
sudo apt install inkscape pandoc texlive-xetex texlive-fonts-recommended texlive-generic-recommended
您可以尝试以下步骤:
pip install --upgrade nbconvert
sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-plain-generic
pip install altair_saver
我在 Ubuntu 上也遇到了这个问题,解决方法是按照 Inkscape Wiki 上建议的安装方式通过 apt 库安装。
sudo apt-get install inkscape
/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:
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”功能正常工作。