500 : Internal Server Error, jinja2 related

Hi,
if I run jupyter via jupyter notebook --no-browser and then create a new Python notebook I have " 500 : Internal Server Error" webpage error.

In the shell I have the below error. How to solve it?

Thank you

    HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/notebooks/Untitled.ipynb?kernel_name=python3', version='HTTP/1.1', remote_ip='127.0.0.1')
    Traceback (most recent call last):
      File "/home/aborruso/.local/lib/python3.9/site-packages/tornado/web.py", line 1704, in _execute
        result = await result
      File "/home/aborruso/.local/lib/python3.9/site-packages/tornado/gen.py", line 775, in run
        yielded = self.gen.send(value)
      File "/home/aborruso/.local/lib/python3.9/site-packages/notebook/notebook/handlers.py", line 95, in get
        self.write(self.render_template('notebook.html',
      File "/home/aborruso/.local/lib/python3.9/site-packages/notebook/base/handlers.py", line 516, in render_template
        return template.render(**ns)
      File "/home/aborruso/.local/lib/python3.9/site-packages/jinja2/environment.py", line 1291, in render
        self.environment.handle_exception()
      File "/home/aborruso/.local/lib/python3.9/site-packages/jinja2/environment.py", line 926, in handle_exception
        raise rewrite_traceback_stack(source=source)
      File "/home/aborruso/.local/lib/python3.9/site-packages/notebook/templates/notebook.html", line 1, in top-level template code
        {% extends "page.html" %}
      File "/home/aborruso/.local/lib/python3.9/site-packages/notebook/templates/page.html", line 154, in top-level template code
        {% block header %}
      File "/home/aborruso/.local/lib/python3.9/site-packages/notebook/templates/notebook.html", line 115, in block 'header'
        {% for exporter in get_frontend_exporters() %}
      File "/home/aborruso/.local/lib/python3.9/site-packages/notebook/notebook/handlers.py", line 23, in get_frontend_exporters
        from nbconvert.exporters.base import get_export_names, get_exporter
      File "/home/aborruso/.local/lib/python3.9/site-packages/nbconvert/__init__.py", line 4, in <module>
        from .exporters import *
      File "/home/aborruso/.local/lib/python3.9/site-packages/nbconvert/exporters/__init__.py", line 3, in <module>
        from .html import HTMLExporter
      File "/home/aborruso/.local/lib/python3.9/site-packages/nbconvert/exporters/html.py", line 14, in <module>
        from jinja2 import contextfilter
    ImportError: cannot import name 'contextfilter' from 'jinja2' (/home/aborruso/.local/lib/python3.9/site-packages/jinja2/__init__.py)
1 Like

I have solved upgrading nbconvert

5 Likes

Upgrading nbconvert solved it

Hello
Nothing is working on my end: I created a new conda environment, upgraded nbconvert, upgraded jinja2, uninstalled and re-installed jupyter-notebook.
I still get the same error: ImportError: cannot import name ‘contextfilter’ from ‘jinja2’

Python 3.9.19
jupyter-notebook 6.0.3
jinja2 3.1.3
nbconvert 7.16.3

I’m grateful if someone has an idea as I cannot open any jupyter-notebooks now

You seem to be using really old Python and Jupyter Notbeook versions with super modern jinga and nbconvert. This does not equate with what you said of making a new conda environment and upgrading things. If you are sure your environments are stored good, you should uninstall and clear out all Anaconda/conda it seems.