命令行输入jupyter notebook提示NotImplementedError(Python3.8)

C:\Users\rayna>jupyter notebook
Traceback (most recent call last):
  File "e:\python\python38\lib\runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "e:\python\python38\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "E:\Python\Python38\Scripts\jupyter-notebook.EXE\__main__.py", line 9, in <module>
  File "e:\python\python38\lib\site-packages\jupyter_core\application.py", line 268, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "e:\python\python38\lib\site-packages\traitlets\config\application.py", line 663, in launch_instance
    app.initialize(argv)
  File "<e:\python\python38\lib\site-packages\decorator.py:decorator-gen-7>", line 2, in initialize
  File "e:\python\python38\lib\site-packages\traitlets\config\application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "e:\python\python38\lib\site-packages\notebook\notebookapp.py", line 1720, in initialize
    self.init_webapp()
  File "e:\python\python38\lib\site-packages\notebook\notebookapp.py", line 1482, in init_webapp
    self.http_server.listen(port, self.ip)
  File "e:\python\python38\lib\site-packages\tornado\tcpserver.py", line 152, in listen
    self.add_sockets(sockets)
  File "e:\python\python38\lib\site-packages\tornado\tcpserver.py", line 165, in add_sockets
    self._handlers[sock.fileno()] = add_accept_handler(
  File "e:\python\python38\lib\site-packages\tornado\netutil.py", line 279, in add_accept_handler
    io_loop.add_handler(sock, accept_handler, IOLoop.READ)
  File "e:\python\python38\lib\site-packages\tornado\platform\asyncio.py", line 99, in add_handler
    self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
  File "e:\python\python38\lib\asyncio\events.py", line 503, in add_reader
    raise NotImplementedError
NotImplementedError

On Windows, Tornado requires the WindowsSelectorEventLoop. This is the default in Python 3.7 and older, but Python 3.8 defaults to an event loop that is not compatible with Tornado. Applications that use Tornado on Windows with Python 3.8 must call asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())at the beginning of their main file/function.

这是python3.8中asyncio默认使用ProactorEventLoop造成的,jupyter 依赖tornado,tornado需使用 SelectorEventLoop。而对于像 jupyter 这种依赖于 tornado 的库,则无法用这种方式。

解决办法: 修改python安装目录(如果忘记安装在哪了看报错的路径信息)\Lib\sitepackages\tornado\platform\asyncio.py文件内容
在这里插入图片描述
在asyncio.py文件中加入

import asyncio
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

在 import asyncio之后手动让 tornado 选择SelectorEventLoop,这样 jupyter 就可以正常使用了。

这时再重新输入命令就好了,页面会自动跳转

C:\Users\rayna>jupyter notebook
[I 22:08:02.710 NotebookApp] JupyterLab extension loaded from e:\python\python38\lib\site-packages\jupyterlab
[I 22:08:02.711 NotebookApp] JupyterLab application directory is e:\python\python38\share\jupyter\lab
[I 22:08:03.660 NotebookApp] Serving notebooks from local directory: C:\Users\rayna
[I 22:08:03.661 NotebookApp] The Jupyter Notebook is running at:
[I 22:08:03.662 NotebookApp] http://localhost:8888/?token=547b9cb38922e7d12fa1f932be6f84ac291ffd4de9723d9a
[I 22:08:03.664 NotebookApp]  or http://127.0.0.1:8888/?token=547b9cb38922e7d12fa1f932be6f84ac291ffd4de9723d9a
[I 22:08:03.665 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 22:08:03.815 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///C:/Users/rayna/AppData/Roaming/jupyter/runtime/nbserver-7948-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=547b9cb38922e7d12fa1f932be6f84ac291ffd4de9723d9a
     or http://127.0.0.1:8888/?token=547b9cb38922e7d12fa1f932be6f84ac291ffd4de9723d9a

在这里插入图片描述
Python目前最新版本是2019年10月14日发布的3.8,从学习与开发角度目前不太建议使用,因为会出现很多其他版本不会出现的问题,而且现有的解决办法还很少。

发布了32 篇原创文章 · 获赞 23 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_35443700/article/details/105056063
今日推荐