spatialaudio / nbsphinx

:ledger: Sphinx source parser for Jupyter notebooks
https://nbsphinx.readthedocs.io/
MIT License
449 stars 128 forks source link

Extension error: Could not import extension nbsphinx (exception: cannot import name 'contextfilter' from 'jinja2') #710

Closed lneuhaus closed 1 year ago

lneuhaus commented 1 year ago

When I try using nbsphinx (latest version from pip 0.8.12) together with the latest version of Jinja2 (3.1.2), I get the following error:

Extension error: Could not import extension nbsphinx (exception: cannot import name 'contextfilter' from 'jinja2') (/home/.../lib/python3.9/site-packages/jinja2/__init__.py)) make: *** [Makefile:60: html] Error 2

I believe jinja2 might have silently broken its public API, or maybe contextfilter was never part of that public API, don't know. Maybe there is a workaround here?

lneuhaus commented 1 year ago

see https://github.com/pallets/jinja/blob/05a5f8120a62f2e1da322131c632be2ba8d969fc/src/jinja2/utils.py#L40 - seems one is supposed to use pass_context() instead of contextfilter now. And in the tagged github version 3.0.0, this change has already happened, but I suppose the PyPI version 3.0.0 is not that one, but maybe corresponds to tag 3.0.0a1 or so https://github.com/pallets/jinja/blob/3.0.0a1/src/jinja2/utils.py or so, where it's still called contextfilter.

lneuhaus commented 1 year ago

Ah, I now see this is a duplicate of https://github.com/jupyter/nbconvert/issues/1742, and it belongs there..