报错解决:jupyter notebook打开显示500 : Internal Server Error

报错解决:jupyter notebook打开显示500 : Internal Server Error

  • 问题
  • 分析
  • 解决

问题

jupyter notebook打开某一ipynb文件后显示报错:

500 : Internal Server Error

示意图如下:
请添加图片描述

Terminal中的报错:

[E 15:38:38.448 NotebookApp] Uncaught exception GET /notebooks/code/Untitled1.ipynb?kernel_name=conda-env-python-py (127.0.0.1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/notebooks/code/Untitled1.ipynb?kernel_name=conda-env-python-py', version='HTTP/1.1', remote_ip='127.0.0.1')
    Traceback (most recent call last):
      File "/home/marcos/anaconda3/envs/python/lib/python3.8/site-packages/tornado/web.py", line 1713, in _execute
        result = await result
      File "/home/marcos/anaconda3/envs/python/lib/python3.8/site-packages/tornado/gen.py", line 782, in run
        yielded = self.gen.send(value)
      File "/home/marcos/anaconda3/envs/python/lib/python3.8/site-packages/notebook/notebook/handlers.py", line 94, in get
        self.write(self.render_template('notebook.html',
      File "/home/marcos/anaconda3/envs/python/lib/python3.8/site-packages/notebook/base/handlers.py", line 511, in render_template
        return template.render(**ns)
      File "/home/marcos/anaconda3/envs/python/lib/python3.8/site-packages/jinja2/environment.py", line 1301, in render
        self.environment.handle_exception()
      File "/home/marcos/anaconda3/envs/python/lib/python3.8/site-packages/jinja2/environment.py", line 936, in handle_exception
        raise rewrite_traceback_stack(source=source)
      File "/home/marcos/anaconda3/envs/python/lib/python3.8/site-packages/notebook/templates/notebook.html", line 1, in top-level template code
        {% extends "page.html" %}
      File "/home/marcos/anaconda3/envs/python/lib/python3.8/site-packages/notebook/templates/page.html", line 166, in top-level template code
        {% block header %}
      File "/home/marcos/anaconda3/envs/python/lib/python3.8/site-packages/notebook/templates/notebook.html", line 115, in block 'header'
        {% for exporter in get_frontend_exporters() %}
      File "/home/marcos/anaconda3/envs/python/lib/python3.8/site-packages/notebook/notebook/handlers.py", line 23, in get_frontend_exporters
        from nbconvert.exporters.base import get_export_names, get_exporter
      File "/home/marcos/anaconda3/envs/python/lib/python3.8/site-packages/nbconvert/__init__.py", line 3, in <module>
        from . import filters, postprocessors, preprocessors, writers
      File "/home/marcos/anaconda3/envs/python/lib/python3.8/site-packages/nbconvert/filters/__init__.py", line 8, in <module>
        from .markdown import *
      File "/home/marcos/anaconda3/envs/python/lib/python3.8/site-packages/nbconvert/filters/markdown.py", line 13, in <module>
        from .markdown_mistune import markdown2html_mistune
      File "/home/marcos/anaconda3/envs/python/lib/python3.8/site-packages/nbconvert/filters/markdown_mistune.py", line 37, in <module>
        class MathBlockGrammar(mistune.BlockGrammar):
    AttributeError: module 'mistune' has no attribute 'BlockGrammar'
[E 15:38:38.452 NotebookApp] {
      "Host": "localhost:8888",
      "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
      "Referer": "http://localhost:8888/tree/code",
      "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"
    }

分析

问题报错的原因在于nbconvert版本不匹配,导致不兼容,需要进行更新。

解决

进入conda环境,输入以下指令:

pip install --upgrade --user nbconvert
# --upgrade 更新包
# --user 将Python包安装到系统目录

注:一般上述代码即可解决问题,若上述方法不可行,可尝试输入以下指令(可选):

pip install --upgrade "ipython[all]"
# 更新ipython的全部包

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
xiaoxingxing的头像xiaoxingxing管理团队
上一篇 2023年7月13日
下一篇 2023年7月13日

相关推荐