【问题标题】:Jupyter Notebook with Python 3.8 - NotImplementedError使用 Python 3.8 的 Jupyter Notebook - NotImplementedError
【发布时间】:2020-02-13 19:06:15
【问题描述】:

最近升级到 Python 3.8,并安装了jupyter。但是,当尝试运行jupyter notebook 时出现以下错误:

  File "c:\users\user\appdata\local\programs\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 "c:\users\user\appdata\local\programs\python\python38\lib\asyncio\events.py", line 501, in add_reader
    raise NotImplementedError
NotImplementedError

我知道 Windows 上的 Python 3.8 默认切换到 ProactorEventLoop,所以我怀疑它与此有关。

Jupyter 目前不支持 Python 3.8?有解决办法吗?

【问题讨论】:

  • Python 3.8 非常新鲜,所以最好回到 3.7 并等待一段时间,直到它得到更好的测试,并且专门为 3.8 创建模块。
  • 在 3.8.1(今天发布)中仍然存在问题。
  • 这个问题现在在 jupyter notebook 的 6.0.3 版本中得到修复。使用pip install notebook --upgrade升级

标签: python windows jupyter-notebook tornado


【解决方案1】:

编辑

此问题存在于旧版本的 Jupyter Notebook 中,并已在版本 6.0.3(2020 年 1 月 21 日发布)中得到修复。要升级到最新版本,请运行:

pip install notebook --upgrade

通过 GitHub 了解了这个问题,看来这个问题与 jupyter 使用的 tornado 服务器有关。

对于那些等不及官方修复的人,我可以通过编辑文件 tornado/platform/asyncio.py 来使其正常工作,并添加:

import sys

if sys.platform == 'win32':
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

主要进口之后。

不过,我预计很快会有官方解决方案。

【讨论】:

  • 不要指望 Tornado 团队会修复:github.com/tornadoweb/tornado/issues/2608
  • 如果您正在寻找 asyncio.py,请查看“C:\Python3\Lib\site-packages\tornado\platform”
  • 谢谢!如果您使用的是 conda env,请确保更改 env 中的版本,而不仅仅是全局版本。其次,确保在import asyncio 语句之后添加此更改:)
  • 这为我解决了问题。特别是: 1. 如果您运行:jupyter -m notebook 2. 在我的系统上,您可以从堆栈跟踪中获取文件位置:C:\Users_NAME_\AppData\Roaming\Python\Python38\site-packages \tornado\platform\asyncio.py
  • 这对我 2020 年 1 月 Python3.8 不起作用,但 Mirwise Khan 的回答如下
【解决方案2】:

2019年修改答案

更改文件的结尾部分 C:\Users\{USER-NAME}\AppData\Local\Programs\Python\Python38\Lib\asyncio\__init__.py

来自

if sys.platform == 'win32':  # pragma: no cover
    from .windows_events import *
    __all__ += windows_events.__all__
else:
    from .unix_events import *  # pragma: no cover
    __all__ += unix_events.__all__

import asyncio

if sys.platform == 'win32':
    from .windows_events import *
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
    __all__ += windows_events.__all__
else:
    from .unix_events import *  # pragma: no cover
    __all__ += unix_events.__all__

【讨论】:

  • 问题和接受的答案都是从 2019 年 10 月开始的,该解决方案对我有用
  • 接受的答案对我不起作用。这样做了。谢谢!
  • 2020 年 1 月的 python 3.8 也为我工作
  • 不会去修改 Python 的标准库源代码。
  • 您可以在其他任何地方执行此操作,例如site.py
【解决方案3】:

对我来说,我不得不重新安装 asyncio

pip install asyncio --upgrade

并升级内核包

pip install ipykernel --upgrade

【讨论】:

    【解决方案4】:

    我通过将 python 版本从 3.9 更改为 3.7 解决了这个问题。 (Windows)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-21
      • 2019-07-15
      • 1970-01-01
      • 1970-01-01
      • 2021-09-30
      • 2017-04-24
      • 1970-01-01
      相关资源
      最近更新 更多