8

Here is the detailed error when launching jupyter notebook with python version 3.8

  File "c:\users\kokat\appdata\local\programs\python\python38\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\kokat\appdata\local\programs\python\python38\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\kokat\AppData\Local\Programs\Python\Python38\Scripts\jupyter-notebook.EXE\__main__.py", line 9, in <module>
  File "c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\jupyter_core\application.py", line 266, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\traitlets\config\application.py", line 657, in launch_instance
    app.initialize(argv)
  File "<c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\decorator.py:decorator-gen-7>", line 2, in initialize
  File "c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\traitlets\config\application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\notebook\notebookapp.py", line 1628, in initialize
    self.init_webapp()
  File "c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\notebook\notebookapp.py", line 1407, in init_webapp
    self.http_server.listen(port, self.ip)
  File "c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\tornado\tcpserver.py", line 144, in listen
    self.add_sockets(sockets)
  File "c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\tornado\tcpserver.py", line 157, in add_sockets
    self._handlers[sock.fileno()] = add_accept_handler(
  File "c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\tornado\netutil.py", line 268, in add_accept_handler
    io_loop.add_handler(sock, accept_handler, IOLoop.READ)
  File "c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\tornado\platform\asyncio.py", line 79, in add_handler
    self.asyncio_loop.add_reader(
  File "c:\users\kokat\appdata\local\programs\python\python38\lib\asyncio\events.py", line 498, in add_reader
    raise NotImplementedError
NotImplementedError

Any helps would be appreciated.

gdlmx
  • 6,479
  • 1
  • 21
  • 39
nikhil kokate
  • 81
  • 1
  • 2
  • 1
    Possibly the same cause as https://stackoverflow.com/questions/54608421/how-to-fix-notimplementederror-when-trying-to-run-hydrogen-in-atom – Fei Feb 21 '19 at 11:30
  • still broken in 3.8.1 (released today). – Rick Dec 19 '19 at 20:11

2 Answers2

8

Following one of the comments in this thread, I've solved the problem by:

  1. Locate and open the asyncio.py file. In my case it's in C:\Users\[USERNAME]\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\tornado\platform\
  2. After the line import asyncio add the following:
from sys import platform 
if platform == "win32":               
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # python-3.8.0a4

This will force using SelectorEventLoop on Windows.

Patrick Klein
  • 1,161
  • 3
  • 10
  • 23
NeverNervous
  • 606
  • 4
  • 8
  • 1
    this answer is also given [here](https://stackoverflow.com/questions/58422817/jupyter-notebook-with-python-3-8-notimplementederror/58430041#58430041) - although 1) the linked question is actually newer therefore a dupe of this one here and 2) it's not even a jupyter issue, it's a problem caused by tornado. – FObersteiner Nov 05 '19 at 17:09
  • 1
    Do note that the path may vary depending on your installation, say for my anaconda based installation and environment. I have to tweak the asyncio.py file @ C:\Users\\[USERNAME]\Anaconda3\envs\\[ENVIRONMENT NAME]\Lib\site-packages\tornado\platform. You may run into this error (only with python 3.8 so far) too if you are using a vscode based setup which launches a jupyter server as the interpretator. – MingH Jan 10 '20 at 08:49
  • This has 0 change for me – ProsperousHeart Mar 25 '20 at 20:34
  • You can, and probably should, do this in your own program file. So that you don't need to depend on a custom modification of another module. – Break Feb 11 '21 at 23:33
5

Jupyter notebook runs as a tornado web server. Your browser connect to this tornado server via a socket.

The I/O of the socket are handled by tornado's asyncio, which relies on the add_reader implementation of the native asyncio module of python runtime. As pointed out in the documentation of asyncio, this method is only supported with Windows SelectorEventLoop so make sure you are using this kind of event loop in your python installation. To find out which eventloop implementation is in usage, you can run the following commands in python shell:

import asyncio
print(asyncio.get_event_loop().__class__)
# Output: <class 'asyncio.windows_events._WindowsSelectorEventLoop'>

There is an ongoing discussion about allowing user to change the EventLoopPolicy of asyncio in jupyter's configuration file.

gdlmx
  • 6,479
  • 1
  • 21
  • 39