When I try to export a Jupyter notebook to pdf format, I receive the following error. nbconvert failed: Inkscape svg to pdf conversion failed. What's causing the error?
When I try to export a Jupyter notebook to pdf format, I receive the following error. nbconvert failed: Inkscape svg to pdf conversion failed. What's causing the error?
This is currently an open issue it seems like: https://github.com/jupyter/nbconvert/issues/1325
But for me installing the nbconvert 6.0.0 version worked. In that version the code that @Raoul mentions has been modified:
pip install nbconvert==6.0.0
You also need to have Inkscape installed + make sure you can open inkscape from the terminal. In MacOS i had to do this:
ln -s /Applications/Inkscape.app/Contents/MacOS/inkscape \
/usr/local/bin/inkscape
I think where exactly the executable is depends on your version of inkscape. But if you have the latest version, it should be the same. Essentially typing inkscape in the terminal should open inkscape. That's what you want.
The error occurs because export to pdf software isn't installed. Use the following commands to install the missing software. Commands shown are for debian distributions such as Ubuntu.
sudo apt update && sudo apt upgrade
sudo apt install inkscape pandoc texlive-xetex texlive-fonts-recommended texlive-generic-recommended
On Mac OSX and Anaconda distribution I was facing the same problem. I discovered that the problem is in the /Applications/anaconda3/lib/python3.7/site-packages/nbconvert/preprocessors/svg2pdf.py file.
According to https://wiki.inkscape.org/wiki/index.php/Using_the_Command_Line inside this file you have some lines (which I commented out) which are obsolete and need to be replaced with the following.
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}"'
Also be sure that you have installed Inkscape:
sudo ln -s /Applications/Inkscape.app/Contents/MacOS/inkscape /usr/local/binAnd I have changed the path:
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
Now the export File > Download As > pdf is working.
You can try the following steps
pip install --upgrade nbconvert
sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-plain-generic
pip install altair_saver