jupyter / nbconvert

Jupyter Notebook Conversion
https://nbconvert.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.75k stars 569 forks source link

Error in docs example: Using nbconvert as a library: KeyError: 'template_paths' #2081

Open psychemedia opened 11 months ago

psychemedia commented 11 months ago

In the docs, an example is given of using nbconvert as a library:

import nbformat
from nbconvert import RSTExporter

# Instantiate exporter
rst_exporter = RSTExporter()

# Read notebook
nb = nbformat.read("demo.ipynb", as_version=4)

# Create exporter
rst_exporter = RSTExporter()

# Export notebook to rst
(body, resources) = rst_exporter.from_notebook_node(nb)
body

This throws an error:

KeyError                                  Traceback (most recent call last)
File [~/Library/Python/3.11/lib/python/site-packages/traitlets/traitlets.py:633] in TraitType.get(self, obj, cls)
    [632] try:
--> [633]  value = obj._trait_values[self.name]
    [634] except KeyError:
    [635]  # Check for a dynamic initializer.

KeyError: 'template_paths'

Running the CLI command works fine.

psychemedia commented 11 months ago

Ah.. I wonder if this is a path problem across various python installations, perhaps with env vars pointing to one Jupyter installation but the code actually running against nbconvert in another environment.