Jupyter Notebook导出失败,提示"nbconvert failed: Inkscape svg to pdf conversion failed"。

4

当我尝试将Jupyter笔记本导出为PDF格式时,我收到以下错误信息:nbconvert失败:Inkscape SVG转PDF转换失败。是什么导致了这个错误?

5个回答

3

目前似乎存在一个开放问题: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,这就是你想要的。


2
错误的原因是未安装导出为pdf格式的软件。请使用以下命令安装缺失的软件。这些命令适用于Debian发行版,如Ubuntu。
sudo apt update && sudo apt upgrade
sudo apt install inkscape pandoc texlive-xetex texlive-fonts-recommended texlive-generic-recommended

1

您可以尝试以下步骤:

  1. pip install --upgrade nbconvert

  2. sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-plain-generic

  3. pip install altair_saver


1

我在 Ubuntu 上也遇到了这个问题,解决方法是按照 Inkscape Wiki 上建议的安装方式通过 apt 库安装。

 sudo apt-get install inkscape

1
在Mac OSX和Anaconda发行版上,我遇到了同样的问题。我发现问题出在/Applications/anaconda3/lib/python3.7/site-packages/nbconvert/preprocessors/svg2pdf.py文件中。
根据https://wiki.inkscape.org/wiki/index.php/Using_the_Command_Line, 在这个文件中,你需要注释掉一些过时的行,并用以下内容替换它们。
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”功能正常工作。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接