记录一次jupyter notebook报错500: Internal Server Error的解决

问题描述:

在notebook中打开.ipynb文件后网页提示500: Internal Server Error
终端显示: AssertionError: wrong color format ‘var(–jp-mirror-editor-variable-color)’

  1. 按照网上大部分博客描述,是因为nbconvert 和pandoc不兼容问题,更新nbconvert 版本:
pip install --upgrade nbconvert

更新后重启jupyter notebook,还是提示500: Internal Server Error

  1. 尝试更新pandoc版本:
pip install --upgrade pandoc

更新后重启jupyter notebook,还是提示500: Internal Server Error
3. 观察报错信息:


    Traceback (most recent call last):
      File "/usr/local/lib/python3.8/dist-packages/tornado/web.py", line 1704, in _execute
        result = await result
      File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 775, in run
        yielded = self.gen.send(value)
      File "/usr/local/lib/python3.8/dist-packages/notebook/notebook/handlers.py", line 95, in get
        self.write(self.render_template('notebook.html',
      File "/usr/local/lib/python3.8/dist-packages/notebook/base/handlers.py", line 516, in render_template
        return template.render(**ns)
      File "/usr/local/lib/python3.8/dist-packages/jinja2/environment.py", line 1304, in render
        self.environment.handle_exception()
      File "/usr/local/lib/python3.8/dist-packages/jinja2/environment.py", line 925, in handle_exception
        raise rewrite_traceback_stack(source=source)
      File "/usr/local/lib/python3.8/dist-packages/notebook/templates/notebook.html", line 1, in top-level template code
        {% extends "page.html" %}
      File "/usr/local/lib/python3.8/dist-packages/notebook/templates/page.html", line 154, in top-level template code
        {% block header %}
      File "/usr/local/lib/python3.8/dist-packages/notebook/templates/notebook.html", line 115, in block 'header'
        {% for exporter in get_frontend_exporters() %}
      File "/usr/local/lib/python3.8/dist-packages/notebook/notebook/handlers.py", line 23, in get_frontend_exporters
        from nbconvert.exporters.base import get_export_names, get_exporter
      File "/usr/local/lib/python3.8/dist-packages/nbconvert/__init__.py", line 4, in 
        from .exporters import *
      File "/usr/local/lib/python3.8/dist-packages/nbconvert/exporters/__init__.py", line 4, in 
        from .slides import SlidesExporter
      File "/usr/local/lib/python3.8/dist-packages/nbconvert/exporters/slides.py", line 12, in 
        from ..preprocessors.base import Preprocessor
      File "/usr/local/lib/python3.8/dist-packages/nbconvert/preprocessors/__init__.py", line 7, in 
        from .csshtmlheader import CSSHTMLHeaderPreprocessor
      File "/usr/local/lib/python3.8/dist-packages/nbconvert/preprocessors/csshtmlheader.py", line 14, in 
        from jupyterlab_pygments import JupyterStyle
      File "/usr/local/lib/python3.8/dist-packages/jupyterlab_pygments/__init__.py", line 4, in 
        from .style import JupyterStyle
      File "/usr/local/lib/python3.8/dist-packages/jupyterlab_pygments/style.py", line 10, in 
        class JupyterStyle(Style):
      File "/usr/lib/python3/dist-packages/pygments/style.py", line 101, in __new__
        ndef[0] = colorformat(styledef)
      File "/usr/lib/python3/dist-packages/pygments/style.py", line 58, in colorformat
        assert False, "wrong color format %r" % text
    AssertionError: wrong color format 'var(--jp-mirror-editor-variable-color)'

涉及pygments模块。于是尝试更新pygments,发现已经是最新版本(2.10)。查阅到StackOverflow上的讨论,将pygments回退到2.6.1就正常了
4. 回退pygments版本

pip install pygments==2.6.1

问题解决。

你可能感兴趣的:(python)