Converting jupyter notebook to pdf - nbconvert

I have been able to use nbconvert in the past, but it isn’t working now. I suspect it is because of my graphs. This is the error that I get:

[NbConvertApp] Converting notebook mlp-week02.ipynb to pdf
Traceback (most recent call last):
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 535, in get
    value = obj._trait_values[self.name]
KeyError: 'command'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 535, in get
    value = obj._trait_values[self.name]
KeyError: 'inkscape_version'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 535, in get
    value = obj._trait_values[self.name]
KeyError: 'inkscape'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 101, in _inkscape_default
    rkey = winreg.OpenKey(wr_handle, "SOFTWARE\\Classes\\inkscape.svg\\DefaultIcon")
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\s1612415\AppData\Local\Programs\Python\Python39\Scripts\jupyter-nbconvert.EXE\__main__.py", line 7, in <module>
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\jupyter_core\application.py", line 254, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\config\application.py", line 845, in launch_instance
    app.start()
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\nbconvertapp.py", line 350, in start
    self.convert_notebooks()
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\nbconvertapp.py", line 524, in convert_notebooks
    self.convert_single_notebook(notebook_filename)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\nbconvertapp.py", line 489, in convert_single_notebook
    output, resources = self.export_single_notebook(notebook_filename, resources, input_buffer=input_buffer)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\nbconvertapp.py", line 418, in export_single_notebook
    output, resources = self.exporter.from_filename(notebook_filename, resources=resources)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\exporter.py", line 181, in from_filename
    return self.from_file(f, resources=resources, **kw)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\exporter.py", line 199, in from_file
    return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\pdf.py", line 168, in from_notebook_node
    latex, resources = super().from_notebook_node(
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\latex.py", line 77, in from_notebook_node
    return super().from_notebook_node(nb, resources, **kw)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\templateexporter.py", line 369, in from_notebook_node
    nb_copy, resources = super().from_notebook_node(nb, resources, **kw)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\exporter.py", line 143, in from_notebook_node
    nb_copy, resources = self._preprocess(nb_copy, resources)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\exporter.py", line 318, in _preprocess
    nbc, resc = preprocessor(nbc, resc)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\base.py", line 47, in __call__
    return self.preprocess(nb, resources)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\base.py", line 69, in preprocess
    nb.cells[index], resources = self.preprocess_cell(cell, resources, index)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\convertfigures.py", line 45, in preprocess_cell
    output.data[self.to_format] = self.convert_figure(
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 125, in convert_figure
    shell = self.command.format(from_filename=input_filename,
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 575, in __get__
    return self.get(obj, cls)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 538, in get
    default = obj.trait_defaults(self.name)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 1578, in trait_defaults
    return self._get_trait_default_generator(names[0])(self)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 975, in __call__
    return self.func(*args, **kwargs)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 77, in _command_default
    major_verison = self.inkscape_version.split('.')[0]
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 575, in __get__
    return self.get(obj, cls)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 538, in get
    default = obj.trait_defaults(self.name)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 1578, in trait_defaults
    return self._get_trait_default_generator(names[0])(self)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 975, in __call__
    return self.func(*args, **kwargs)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 57, in _inkscape_version_default
    p = subprocess.Popen([self.inkscape, '--version'],
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 575, in __get__
    return self.get(obj, cls)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 538, in get
    default = obj.trait_defaults(self.name)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 1578, in trait_defaults
    return self._get_trait_default_generator(names[0])(self)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 975, in __call__
    return self.func(*args, **kwargs)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 104, in _inkscape_default
    raise FileNotFoundError("Inkscape executable not found")
FileNotFoundError: Inkscape executable not found

I have installed Inkscape and added the inkscape.exe file to PATH (was I supposed to?), but it still doesn’t work. Any advice?

Have you tried to switch it off and on again? Well, seriously, after installing the updated PATH variable might not be available to all processes, see e.g. this for reference.

For readability and activating scrol features, please encapsulate your error logs with three backticks (```) on an empty line each.

I have restarted the notebook and my computer. Still doesn’t work.

Then I guess you did not correctly add inkscape to your PATH variable. Because it should work. Maybe you can check in the Jupyter Notebook which paths you have in the PATH variable and share all of them ? Did you add the folder of inkscape.exe to the path variable? How did you add it?

I am on Windows, so I went to ‘System Properties’ > ‘Environment Variables’ > ‘Path’ > ‘Edit…’. Then I added ‘C:\Program Files\Inkscape\inkscape.exe’.

As you can see on Wikipedia, you should add the folder of the executable to the path, i.e. C:\Program Files\Inkscape\, and not the path to the EXE file.

I have tried both ways, it still doesn’t work.

[NbConvertApp] Converting notebook mlp-week02.ipynb to pdf
Traceback (most recent call last):
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 535, in get
    value = obj._trait_values[self.name]
KeyError: 'command'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 535, in get
    value = obj._trait_values[self.name]
KeyError: 'inkscape_version'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 535, in get
    value = obj._trait_values[self.name]
KeyError: 'inkscape'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 101, in _inkscape_default
    rkey = winreg.OpenKey(wr_handle, "SOFTWARE\\Classes\\inkscape.svg\\DefaultIcon")
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\s1612415\AppData\Local\Programs\Python\Python39\Scripts\jupyter-nbconvert.EXE\__main__.py", line 7, in <module>
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\jupyter_core\application.py", line 254, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\config\application.py", line 845, in launch_instance
    app.start()
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\nbconvertapp.py", line 350, in start
    self.convert_notebooks()
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\nbconvertapp.py", line 524, in convert_notebooks
    self.convert_single_notebook(notebook_filename)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\nbconvertapp.py", line 489, in convert_single_notebook
    output, resources = self.export_single_notebook(notebook_filename, resources, input_buffer=input_buffer)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\nbconvertapp.py", line 418, in export_single_notebook
    output, resources = self.exporter.from_filename(notebook_filename, resources=resources)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\exporter.py", line 181, in from_filename
    return self.from_file(f, resources=resources, **kw)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\exporter.py", line 199, in from_file
    return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\pdf.py", line 168, in from_notebook_node
    latex, resources = super().from_notebook_node(
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\latex.py", line 77, in from_notebook_node
    return super().from_notebook_node(nb, resources, **kw)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\templateexporter.py", line 369, in from_notebook_node
    nb_copy, resources = super().from_notebook_node(nb, resources, **kw)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\exporter.py", line 143, in from_notebook_node
    nb_copy, resources = self._preprocess(nb_copy, resources)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\exporter.py", line 318, in _preprocess
    nbc, resc = preprocessor(nbc, resc)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\base.py", line 47, in __call__
    return self.preprocess(nb, resources)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\base.py", line 69, in preprocess
    nb.cells[index], resources = self.preprocess_cell(cell, resources, index)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\convertfigures.py", line 45, in preprocess_cell
    output.data[self.to_format] = self.convert_figure(
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 125, in convert_figure
    shell = self.command.format(from_filename=input_filename,
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 575, in __get__
    return self.get(obj, cls)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 538, in get
    default = obj.trait_defaults(self.name)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 1578, in trait_defaults
    return self._get_trait_default_generator(names[0])(self)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 975, in __call__
    return self.func(*args, **kwargs)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 77, in _command_default
    major_verison = self.inkscape_version.split('.')[0]
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 575, in __get__
    return self.get(obj, cls)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 538, in get
    default = obj.trait_defaults(self.name)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 1578, in trait_defaults
    return self._get_trait_default_generator(names[0])(self)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 975, in __call__
    return self.func(*args, **kwargs)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 57, in _inkscape_version_default
    p = subprocess.Popen([self.inkscape, '--version'],
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 575, in __get__
    return self.get(obj, cls)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 538, in get
    default = obj.trait_defaults(self.name)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 1578, in trait_defaults
    return self._get_trait_default_generator(names[0])(self)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 975, in __call__
    return self.func(*args, **kwargs)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 104, in _inkscape_default
    raise FileNotFoundError("Inkscape executable not found")
FileNotFoundError: Inkscape executable not found

I am getting a new error today:

[NbConvertApp] Converting notebook mlp-week02.ipynb to pdf
Traceback (most recent call last):
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 535, in get
    value = obj._trait_values[self.name]
KeyError: 'command'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 535, in get
    value = obj._trait_values[self.name]
KeyError: 'inkscape_version'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\s1612415\AppData\Local\Programs\Python\Python39\Scripts\jupyter-nbconvert.EXE\__main__.py", line 7, in <module>
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\jupyter_core\application.py", line 254, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\config\application.py", line 845, in launch_instance
    app.start()
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\nbconvertapp.py", line 350, in start
    self.convert_notebooks()
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\nbconvertapp.py", line 524, in convert_notebooks
    self.convert_single_notebook(notebook_filename)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\nbconvertapp.py", line 489, in convert_single_notebook
    output, resources = self.export_single_notebook(notebook_filename, resources, input_buffer=input_buffer)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\nbconvertapp.py", line 418, in export_single_notebook
    output, resources = self.exporter.from_filename(notebook_filename, resources=resources)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\exporter.py", line 181, in from_filename
    return self.from_file(f, resources=resources, **kw)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\exporter.py", line 199, in from_file
    return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\pdf.py", line 168, in from_notebook_node
    latex, resources = super().from_notebook_node(
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\latex.py", line 77, in from_notebook_node
    return super().from_notebook_node(nb, resources, **kw)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\templateexporter.py", line 369, in from_notebook_node
    nb_copy, resources = super().from_notebook_node(nb, resources, **kw)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\exporter.py", line 143, in from_notebook_node
    nb_copy, resources = self._preprocess(nb_copy, resources)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\exporters\exporter.py", line 318, in _preprocess
    nbc, resc = preprocessor(nbc, resc)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\base.py", line 47, in __call__
    return self.preprocess(nb, resources)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\base.py", line 69, in preprocess
    nb.cells[index], resources = self.preprocess_cell(cell, resources, index)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\convertfigures.py", line 45, in preprocess_cell
    output.data[self.to_format] = self.convert_figure(
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 125, in convert_figure
    shell = self.command.format(from_filename=input_filename,
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 575, in __get__
    return self.get(obj, cls)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 538, in get
    default = obj.trait_defaults(self.name)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 1578, in trait_defaults
    return self._get_trait_default_generator(names[0])(self)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 975, in __call__
    return self.func(*args, **kwargs)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 77, in _command_default
    major_verison = self.inkscape_version.split('.')[0]
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 575, in __get__
    return self.get(obj, cls)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 538, in get
    default = obj.trait_defaults(self.name)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 1578, in trait_defaults
    return self._get_trait_default_generator(names[0])(self)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\traitlets\traitlets.py", line 975, in __call__
    return self.func(*args, **kwargs)
  File "c:\users\s1612415\appdata\local\programs\python\python39\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 63, in _inkscape_version_default
    return output.decode('utf-8').split(' ')[1]
IndexError: list index out of range

I guess the new error message is the result of adjusting the PATH variable and restarting the computer. For the new error message I have no idea. Please tell us once you have found a solution.