【问题标题】:Jupyter Notebook Export Fails with "nbconvert failed: Inkscape svg to pdf conversion failed"Jupyter Notebook 导出失败并显示“nbconvert failed: Inkscape svg to pdf conversion failed”
【发布时间】:2020-07-24 15:17:18
【问题描述】:

当我尝试将 Jupyter 笔记本导出为 pdf 格式时,我收到以下错误。 nbconvert failed: Inkscape svg to pdf conversion failed。是什么导致了错误?

【问题讨论】:

    标签: jupyter-notebook jupyter-lab tex inkscape export-to-pdf


    【解决方案1】:

    目前这是一个未解决的问题,看起来像: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 软件。使用以下命令安装缺少的软件。显示的命令适用于 Ubuntu 等 debian 发行版。

      sudo apt update && sudo apt upgrade
      sudo apt install inkscape pandoc texlive-xetex texlive-fonts-recommended texlive-generic-recommended
      

      【讨论】:

        【解决方案3】:

        在 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 正在工作。

        【讨论】:

          【解决方案4】:

          您可以尝试以下步骤

          1. pip install --upgrade nbconvert

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

          3. pip install altair_saver

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2019-08-27
            • 2019-06-27
            • 2022-10-12
            • 1970-01-01
            • 1970-01-01
            • 2019-04-26
            • 2021-08-03
            • 1970-01-01
            相关资源
            最近更新 更多