打开jupyter 报错500

[I 09:31:52.169 NotebookApp] Creating new notebook in
[E 09:31:52.219 NotebookApp] Uncaught exception GET /notebooks/Untitled3.ipynb?kernel_name=python3 (::1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/notebooks/Untitled3.ipynb?kernel_name=python3', version='HTTP/1.1', remote_ip='::1')
    Traceback (most recent call last):
      File "C:\Users\dell\Anaconda3\lib\site-packages\tornado\web.py", line 1713, in _execute
        result = await result
      File "C:\Users\dell\Anaconda3\lib\site-packages\tornado\gen.py", line 782, in run
        yielded = self.gen.send(value)
      File "C:\Users\dell\Anaconda3\lib\site-packages\notebook\notebook\handlers.py", line 100, in get
        get_frontend_exporters=get_frontend_exporters
      File "C:\Users\dell\Anaconda3\lib\site-packages\notebook\base\handlers.py", line 511, in render_template
        return template.render(**ns)
      File "C:\Users\dell\Anaconda3\lib\site-packages\jinja2\environment.py", line 1301, in render
        self.environment.handle_exception()
      File "C:\Users\dell\Anaconda3\lib\site-packages\jinja2\environment.py", line 936, in handle_exception
        raise rewrite_traceback_stack(source=source)
      File "C:\Users\dell\Anaconda3\lib\site-packages\notebook\templates\notebook.html", line 1, in top-level template code
        {% extends "page.html" %}
      File "C:\Users\dell\Anaconda3\lib\site-packages\notebook\templates\page.html", line 154, in top-level template code
        {% block header %}
      File "C:\Users\dell\Anaconda3\lib\site-packages\notebook\templates\notebook.html", line 115, in block 'header'
        {% for exporter in get_frontend_exporters() %}
      File "C:\Users\dell\Anaconda3\lib\site-packages\notebook\notebook\handlers.py", line 23, in get_frontend_exporters
        from nbconvert.exporters.base import get_export_names, get_exporter
      File "C:\Users\dell\Anaconda3\lib\site-packages\nbconvert\__init__.py", line 6, in <module>
        from . import filters, postprocessors, preprocessors, writers
      File "C:\Users\dell\Anaconda3\lib\site-packages\nbconvert\filters\__init__.py", line 11, in <module>
        from .strings import *
      File "C:\Users\dell\Anaconda3\lib\site-packages\nbconvert\filters\strings.py", line 23, in <module>
        from nbconvert.preprocessors.sanitize import _get_default_css_sanitizer
      File "C:\Users\dell\Anaconda3\lib\site-packages\nbconvert\preprocessors\__init__.py", line 13, in <module>
        from .execute import ExecutePreprocessor
      File "C:\Users\dell\Anaconda3\lib\site-packages\nbconvert\preprocessors\execute.py", line 6, in <module>
        from nbclient import NotebookClient
      File "C:\Users\dell\Anaconda3\lib\site-packages\nbclient\__init__.py", line 5, in <module>
        from .client import NotebookClient, execute  # noqa: F401
      File "C:\Users\dell\Anaconda3\lib\site-packages\nbclient\client.py", line 30, in <module>
        from .util import ensure_async, run_hook, run_sync
      File "C:\Users\dell\Anaconda3\lib\site-packages\nbclient\util.py", line 9, in <module>
        from jupyter_core.utils import ensure_async, run_sync  # noqa: F401
    ImportError: cannot import name 'ensure_async' from 'jupyter_core.utils' (C:\Users\dell\Anaconda3\lib\site-packages\jupyter_core\utils\__init__.py)
[E 09:31:52.221 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.7",
      "Referer": "http://localhost:8888/tree",
      "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0"
    }
[E 09:31:52.222 NotebookApp] 500 GET /notebooks/Untitled3.ipynb?kernel_name=python3 (::1) 8.580000ms referer=http://localhost:8888/tree

由于无法从jupyter_core.utils正确导入ensure_async引起的。这类错误可能由几个原因导致,比如安装损坏、Python包版本不兼容或缺少依赖项。以下是一些建议的解决方法:

1、更新jupyter_core及相关包

conda update conda
conda update --all

2、重新安装Jupyter和nbconvert

如果更新操作未能解决问题,你可能需要重新安装Jupyter和nbconvert。你可以使用以下命令来完成:

conda remove jupyter jupyter_core nbconvert nbclient jupyterlab notebook
conda clean -ay
conda install jupyter jupyterlab notebook

这个过程会移除Jupyter生态系统的相关包然后重新安装它们,可能会解决任何冲突或损坏的文件问题。

3、如果仍然打不开,强制重装jupyter_core和nbclient

conda install jupyter_core --force-reinstall
conda install nbclient --force-reinstall

4、运行Jupyter Notebook,此时已经可以正常打开

更多推荐