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?

4
  • 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. Commented Oct 17, 2019 at 1:06
  • 1
    Possible duplicate of Jupyter notebook cannot start with python 3.8 in Windows 10 Commented Nov 5, 2019 at 17:07
  • 3
    still broken in 3.8.1 (released today). Commented Dec 19, 2019 at 20:11
  • 2
    This is now fixed in version 6.0.3 of jupyter notebook. Upgrade with pip install notebook --upgrade Commented Jan 22, 2020 at 12:33

4 Answers 4

201
+100

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.

Sign up to request clarification or add additional context in comments.

13 Comments

Do not expect a fix from Tornado team: github.com/tornadoweb/tornado/issues/2608
if you were looking for asyncio.py, take a look at "C:\Python3\Lib\site-packages\tornado\platform"
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 :)
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
This didn't work for me January 2020, Python3.8 but Mirwise Khan's answer below did
|
45

Revising the answer in 2020

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__

7 Comments

Both the question and accepted answer were from October 2019 and the solution worked for me
The accepted answer didn't work for me. this did. Thanks!
Worked for me too, python 3.8 in jan 2020
I would not go and alter Python's standard library source code.
You can do this anywhere else, like in site.py.
|
3

For me, I had to reinstall asyncio

pip install asyncio --upgrade

And upgrade the kernel package

pip install ipykernel --upgrade

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.