今天使用jupyter notebook时出错:
500: Internal Server Error
错误现象
查看日志:
AssertionError: wrong color format 'var(--jp-mirror-editor-variable-color)'
[E 13:56:50.149 NotebookApp] Uncaught exception GET /notebooks/MongoDB-Soul.ipynb (127.0.0.1)HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/notebooks/MongoDB-Soul.ipynb', version='HTTP/1.1', remote_ip='127.0.0.1')Traceback (most recent call last):File "D:\ProgramData\Anaconda3\lib\site-packages\tornado\web.py", line 1703, in _executeresult = await resultFile "D:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 748, in runyielded = self.gen.send(value)File "D:\ProgramData\Anaconda3\lib\site-packages\notebook\notebook\handlers.py", line 95, in getself.write(self.render_template('notebook.html',File "D:\ProgramData\Anaconda3\lib\site-packages\notebook\base\handlers.py", line 512, in render_templatereturn template.render(**ns)File "D:\ProgramData\Anaconda3\lib\site-packages\jinja2\environment.py", line 1090, in renderself.environment.handle_exception()File "D:\ProgramData\Anaconda3\lib\site-packages\jinja2\environment.py", line 832, in handle_exceptionreraise(*rewrite_traceback_stack(source=source))File "D:\ProgramData\Anaconda3\lib\site-packages\jinja2\_compat.py", line 28, in reraiseraise value.with_traceback(tb)File "D:\ProgramData\Anaconda3\lib\site-packages\notebook\templates\notebook.html", line 1, in top-level template code{% extends "page.html" %}File "D:\ProgramData\Anaconda3\lib\site-packages\notebook\templates\page.html", line 154, in top-level template code{% block header %}File "D:\ProgramData\Anaconda3\lib\site-packages\notebook\templates\notebook.html", line 115, in block "header"{% for exporter in get_frontend_exporters() %}File "D:\ProgramData\Anaconda3\lib\site-packages\notebook\notebook\handlers.py", line 40, in get_frontend_exportersfor name in get_export_names():File "D:\ProgramData\Anaconda3\lib\site-packages\nbconvert\exporters\base.py", line 141, in get_export_namese = get_exporter(exporter_name)(config=config)File "D:\ProgramData\Anaconda3\lib\site-packages\nbconvert\exporters\base.py", line 101, in get_exporterexporter = entrypoints.get_single('nbconvert.exporters', name).load()File "D:\ProgramData\Anaconda3\lib\site-packages\entrypoints.py", line 82, in loadmod = import_module(self.module_name)File "D:\ProgramData\Anaconda3\lib\importlib\__init__.py", line 127, in import_modulereturn _bootstrap._gcd_import(name[level:], package, level)File "<frozen importlib._bootstrap>", line 1014, in _gcd_importFile "<frozen importlib._bootstrap>", line 991, in _find_and_loadFile "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlockedFile "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removedFile "<frozen importlib._bootstrap>", line 1014, in _gcd_importFile "<frozen importlib._bootstrap>", line 991, in _find_and_loadFile "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlockedFile "<frozen importlib._bootstrap>", line 671, in _load_unlockedFile "<frozen importlib._bootstrap_external>", line 783, in exec_moduleFile "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removedFile "D:\ProgramData\Anaconda3\lib\site-packages\nbconvert\__init__.py", line 6, in <module>from . import preprocessorsFile "D:\ProgramData\Anaconda3\lib\site-packages\nbconvert\preprocessors\__init__.py", line 7, in <module>from .csshtmlheader import CSSHTMLHeaderPreprocessorFile "D:\ProgramData\Anaconda3\lib\site-packages\nbconvert\preprocessors\csshtmlheader.py", line 14, in <module>from jupyterlab_pygments import JupyterStyleFile "D:\ProgramData\Anaconda3\lib\site-packages\jupyterlab_pygments\__init__.py", line 4, in <module>from .style import JupyterStyleFile "D:\ProgramData\Anaconda3\lib\site-packages\jupyterlab_pygments\style.py", line 10, in <module>class JupyterStyle(Style):File "D:\ProgramData\Anaconda3\lib\site-packages\pygments\style.py", line 101, in __new__elif styledef == 'nobold':File "D:\ProgramData\Anaconda3\lib\site-packages\pygments\style.py", line 58, in colorformatclass StyleMeta(type):AssertionError: wrong color format 'var(--jp-mirror-editor-variable-color)'
[E 13:56:50.158 NotebookApp] {"Host": "localhost:8888","User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8","Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2","Accept-Encoding": "gzip, deflate","Referer": "http://localhost:8888/tree","Connection": "keep-alive","Cookie": "username-localhost-8889=\"2|1:0|10:1637236743|23:username-localhost-8889|44:OTBlZTk3MjlmODIzNGExYWFhYzQ3NTZiMmI2MTUwZTM=|450fdc6992b203dce4879f1bb2579100393b21469e186b86d457fd4fb7a00cae\"; username-localhost-8888=\"2|1:0|10:1639806888|23:username-localhost-8888|44:N2E2ODQ2OTIzZDBkNGNiMDkwYjgwMGI1MmUyYjMzNDQ=|673adeb337c2039f53c098181781aff7f6cf206d6f765b3afbe609c2222f4150\"; _xsrf=2|4adf7ea7|20b2bab02e528e4a53ea58a131398aff|1639806684","Upgrade-Insecure-Requests": "1","Sec-Fetch-Dest": "document","Sec-Fetch-Mode": "navigate","Sec-Fetch-Site": "same-origin","Sec-Fetch-User": "?1","Cache-Control": "max-age=0"}
[E 13:56:50.158 NotebookApp] 500 GET /notebooks/MongoDB-Soul.ipynb (127.0.0.1) 176.90ms referer=http://localhost:8888/tree
[E 13:56:51.252 NotebookApp] Uncaught exception GET /notebooks/MongoDB-Soul.ipynb (127.0.0.1)HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/notebooks/MongoDB-Soul.ipynb', version='HTTP/1.1', remote_ip='127.0.0.1')Traceback (most recent call last):File "D:\ProgramData\Anaconda3\lib\site-packages\tornado\web.py", line 1703, in _executeresult = await resultFile "D:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 748, in runyielded = self.gen.send(value)File "D:\ProgramData\Anaconda3\lib\site-packages\notebook\notebook\handlers.py", line 95, in getself.write(self.render_template('notebook.html',File "D:\ProgramData\Anaconda3\lib\site-packages\notebook\base\handlers.py", line 512, in render_templatereturn template.render(**ns)File "D:\ProgramData\Anaconda3\lib\site-packages\jinja2\environment.py", line 1090, in renderself.environment.handle_exception()File "D:\ProgramData\Anaconda3\lib\site-packages\jinja2\environment.py", line 832, in handle_exceptionreraise(*rewrite_traceback_stack(source=source))File "D:\ProgramData\Anaconda3\lib\site-packages\jinja2\_compat.py", line 28, in reraiseraise value.with_traceback(tb)File "D:\ProgramData\Anaconda3\lib\site-packages\notebook\templates\notebook.html", line 1, in top-level template code{% extends "page.html" %}File "D:\ProgramData\Anaconda3\lib\site-packages\notebook\templates\page.html", line 154, in top-level template code{% block header %}File "D:\ProgramData\Anaconda3\lib\site-packages\notebook\templates\notebook.html", line 115, in block "header"{% for exporter in get_frontend_exporters() %}File "D:\ProgramData\Anaconda3\lib\site-packages\notebook\notebook\handlers.py", line 40, in get_frontend_exportersfor name in get_export_names():File "D:\ProgramData\Anaconda3\lib\site-packages\nbconvert\exporters\base.py", line 141, in get_export_namese = get_exporter(exporter_name)(config=config)File "D:\ProgramData\Anaconda3\lib\site-packages\nbconvert\exporters\base.py", line 102, in get_exporterif getattr(exporter(config=config), 'enabled', True):File "D:\ProgramData\Anaconda3\lib\site-packages\nbconvert\exporters\templateexporter.py", line 325, in __init__self.observe(self._invalidate_environment_cache,File "D:\ProgramData\Anaconda3\lib\site-packages\nbconvert\exporters\exporter.py", line 114, in __init__File "D:\ProgramData\Anaconda3\lib\site-packages\nbconvert\exporters\templateexporter.py", line 490, in _init_preprocessorspreprocessors = conf.get('preprocessors', {})File "D:\ProgramData\Anaconda3\lib\site-packages\nbconvert\exporters\exporter.py", line 262, in _init_preprocessorsfor preprocessor in self.default_preprocessors:File "D:\ProgramData\Anaconda3\lib\site-packages\nbconvert\exporters\exporter.py", line 227, in register_preprocessor# this register_preprocessor methodFile "D:\ProgramData\Anaconda3\lib\site-packages\traitlets\utils\importstring.py", line 30, in import_itemmodule = __import__(package, fromlist=[obj])File "D:\ProgramData\Anaconda3\lib\site-packages\nbconvert\__init__.py", line 6, in <module>from . import preprocessorsFile "D:\ProgramData\Anaconda3\lib\site-packages\nbconvert\preprocessors\__init__.py", line 7, in <module>from .csshtmlheader import CSSHTMLHeaderPreprocessorFile "D:\ProgramData\Anaconda3\lib\site-packages\nbconvert\preprocessors\csshtmlheader.py", line 14, in <module>from jupyterlab_pygments import JupyterStyleFile "D:\ProgramData\Anaconda3\lib\site-packages\jupyterlab_pygments\__init__.py", line 4, in <module>from .style import JupyterStyleFile "D:\ProgramData\Anaconda3\lib\site-packages\jupyterlab_pygments\style.py", line 10, in <module>class JupyterStyle(Style):File "D:\ProgramData\Anaconda3\lib\site-packages\pygments\style.py", line 101, in __new__elif styledef == 'nobold':File "D:\ProgramData\Anaconda3\lib\site-packages\pygments\style.py", line 58, in colorformatclass StyleMeta(type):AssertionError: wrong color format 'var(--jp-mirror-editor-variable-color)'
[E 13:56:51.259 NotebookApp] {"Host": "localhost:8888","User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8","Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2","Accept-Encoding": "gzip, deflate","Referer": "http://localhost:8888/tree","Connection": "keep-alive","Cookie": "username-localhost-8889=\"2|1:0|10:1637236743|23:username-localhost-8889|44:OTBlZTk3MjlmODIzNGExYWFhYzQ3NTZiMmI2MTUwZTM=|450fdc6992b203dce4879f1bb2579100393b21469e186b86d457fd4fb7a00cae\"; username-localhost-8888=\"2|1:0|10:1639806888|23:username-localhost-8888|44:N2E2ODQ2OTIzZDBkNGNiMDkwYjgwMGI1MmUyYjMzNDQ=|673adeb337c2039f53c098181781aff7f6cf206d6f765b3afbe609c2222f4150\"; _xsrf=2|4adf7ea7|20b2bab02e528e4a53ea58a131398aff|1639806684","Upgrade-Insecure-Requests": "1","Sec-Fetch-Dest": "document","Sec-Fetch-Mode": "navigate","Sec-Fetch-Site": "same-origin","Sec-Fetch-User": "?1","Cache-Control": "max-age=0"}
[E 13:56:51.259 NotebookApp] 500 GET /notebooks/MongoDB-Soul.ipynb (127.0.0.1) 127.86ms referer=http://localhost:8888/tree
原因
这是由 nbconvert
库的不兼容版本引起的。 如果没有将 nbconvert
固定到正确的版本,则可能会意外通过 PyPI 安装不兼容的版本。
解决方案
手动安装 nbconvert
版本 6.0.0rc0。 这将重写可能已安装的库的任何不正确版本。
pip install nbconvert==6.0.0rc0
重启jupyter notebook即可正常运行