78

Upgraded recently to Python 3.8, and installed jupyter. However, when trying to run jupyter notebook getting the following error:

  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

I know Python 3.8 on windows switched to ProactorEventLoop by default, so I suspect it is related to this.

Jupyter does not support Python 3.8 at the moment? Is there a work around?

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
drec4s
  • 7,946
  • 8
  • 33
  • 54
  • 3
    Python 3.8 is very fresh so better go back to 3.7 and wait some time till it will be better tested and modules will be create specially for 3.8. – furas Oct 17 '19 at 01:06
  • 1
    Possible duplicate of [Jupyter notebook cannot start with python 3.8 in Windows 10](https://stackoverflow.com/questions/54805213/jupyter-notebook-cannot-start-with-python-3-8-in-windows-10) – FObersteiner Nov 05 '19 at 17:07
  • 3
    still broken in 3.8.1 (released today). – Rick Dec 19 '19 at 20:11
  • 2
    This is now fixed in version 6.0.3 of jupyter notebook. Upgrade with `pip install notebook --upgrade` – drec4s Jan 22 '20 at 12:33

4 Answers4

201

EDIT

This issue exists in older versions of Jupyter Notebook and was fixed in version 6.0.3 (released 2020-01-21). To upgrade to the latest version run:

pip install notebook --upgrade

Following on this issue through GitHub, it seems the problem is related to the tornado server that jupyter uses.

For those that can't wait for an official fix, I was able to get it working by editing the file tornado/platform/asyncio.py, by adding:

import sys

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

After the main imports.

I expect an official fix for this soon, however.

Udi
  • 29,222
  • 9
  • 96
  • 129
drec4s
  • 7,946
  • 8
  • 33
  • 54
  • 7
    Do not expect a fix from Tornado team: https://github.com/tornadoweb/tornado/issues/2608 – Andrew Oct 18 '19 at 09:22
  • 9
    if you were looking for asyncio.py, take a look at "C:\Python3\Lib\site-packages\tornado\platform" – Bheid Nov 11 '19 at 10:25
  • 2
    Thanks! If you're using a conda env, Make sure to change the version in the env and not only the global one. Second, make sure you add this change after the `import asyncio` statement :) – Omri374 Nov 20 '19 at 09:37
  • 1
    This fixed it for me. In particular: 1. You can get the file location from the stack trace if you run: jupyter -m notebook 2. On my system the file is located here: C:\Users\_NAME_\AppData\Roaming\Python\Python38\site-packages\tornado\platform\asyncio.py – Isaiah Hines Dec 15 '19 at 02:34
  • This worked for me. If you use virtualenv, this fix needs be applied only to your environment in ENV-DIRECTORY\Lib\site-packages\tornado\platform\asyncio.py – Andi Schroff Jan 13 '20 at 16:31
  • 2
    This didn't work for me January 2020, Python3.8 but Mirwise Khan's answer below did – Worm Jan 23 '20 at 10:47
  • I have the latest and it is not fixed. – ProsperousHeart Mar 25 '20 at 20:35
  • 1
    the 'notebook --upgrade' might fix Jupyter Notebook; however, the tornado/asyncio modification for windows platform is still needed e.g. to [run the latest version of Spyder](https://stackoverflow.com/questions/58557238/spyder-ide-fails-to-start-on-windows-10-with-python-3-8), so you might want to keep the workaround in the answer. – FObersteiner Apr 24 '20 at 05:53
  • I tried the notebook upgrade, and even delete it and reinstall, but I still got the problem. I finally used the fix in the `tornado\platform\asyncio.py`. – theFrok May 13 '20 at 07:01
  • may I ask how to update python version **from** 3.7.7 **to** 3.8 via **conda** command or manually within anaconda app on macOS? – Nihat May 13 '20 at 12:41
  • Tornado 6.0.4, Note that it is still necessary to use asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) for this platform/version. https://www.tornadoweb.org/en/stable/releases/v6.0.4.html#general-changes – caoanan Jul 01 '20 at 08:32
  • Upgrading only jupyter didn't do it for me. I also had to update `ipykernel` seperately. – Mac C. Oct 15 '20 at 13:49
  • Updating notebook did not work in my case, inserting the code block solved it instead. – Crispy13 Nov 30 '20 at 07:34
45

Revising the answer in 2019

Change the end part of the file C:\Users\{USER-NAME}\AppData\Local\Programs\Python\Python38\Lib\asyncio\__init__.py

From

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__

To

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__
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Mirwise Khan
  • 1,317
  • 17
  • 25
3

For me, I had to reinstall asyncio

pip install asyncio --upgrade

And upgrade the kernel package

pip install ipykernel --upgrade
penguins
  • 76
  • 8
0

I solved this problem by changing the python version from 3.9 to 3.7. (Windows).

ming
  • 427
  • 1
  • 5
  • 14