14

I am using Jupyter Notebook in Windows 10 with Python 3.9.6. I have installed Jupyter Notebook with this command pip install jupyter and run it with this command jupyter notebook. So after starting the notebook, in the terminal I see some errors also but so far I don't seem to see any impact because of it. But still wanted to check, what that error actually indicates and is there a way to fix it?

[I 18:25:02.479 NotebookApp] Serving notebooks from local directory: C:\Users\maryo\Desktop\python\jpnb
[I 18:25:02.479 NotebookApp] Jupyter Notebook 6.4.3 is running at:
[I 18:25:02.479 NotebookApp] http://localhost:8888/?token=dfd2534b828985fcc116e9c400fd31381e9c8f19034e39d3
[I 18:25:02.479 NotebookApp]  or http://127.0.0.1:8888/?token=dfd2534b828985fcc116e9c400fd31381e9c8f19034e39d3
[I 18:25:02.479 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 18:25:02.508 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///C:/Users/maryo/AppData/Roaming/jupyter/runtime/nbserver-17088-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=dfd2534b828985fcc116e9c400fd31381e9c8f19034e39d3
     or http://127.0.0.1:8888/?token=dfd2534b828985fcc116e9c400fd31381e9c8f19034e39d3
c:\users\maryo\appdata\local\programs\python\python39\lib\json\encoder.py:257: UserWarning: date_default is deprecated since jupyter_client 7.0.0. Use jupyter_client.jsonutil.json_default.
  return _iterencode(o, 0)
[W 18:27:49.960 NotebookApp] Notebook Covid Data Analysis.ipynb is not trusted
ERROR:asyncio:Exception in callback <TaskStepMethWrapper object at 0x000002C98ECD81F0>()
handle: <Handle <TaskStepMethWrapper object at 0x000002C98ECD81F0>()>
Traceback (most recent call last):
  File "c:\users\maryo\appdata\local\programs\python\python39\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
RuntimeError: Cannot enter into task <Task pending name='Task-41' coro=<RequestHandler._execute() running at C:\Users\maryo\Desktop\python\jpnb\lib\site-packages\tornado\web.py:1660> cb=[_HandlerDelegate.execute.<locals>.<lambda>() at C:\Users\maryo\Desktop\python\jpnb\lib\site-packages\tornado\web.py:2326]> while another task <Task pending name='Task-40' coro=<MappingKernelManager.start_kernel() running at C:\Users\maryo\Desktop\python\jpnb\lib\site-packages\notebook\services\kernels\kernelmanager.py:176> cb=[IOLoop.add_future.<locals>.<lambda>() at C:\Users\maryo\Desktop\python\jpnb\lib\site-packages\tornado\ioloop.py:688]> is being executed.
ERROR:asyncio:Exception in callback <TaskStepMethWrapper object at 0x000002C98DA94880>()
handle: <Handle <TaskStepMethWrapper object at 0x000002C98DA94880>()>
Traceback (most recent call last):
  File "c:\users\maryo\appdata\local\programs\python\python39\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
RuntimeError: Cannot enter into task <Task pending name='Task-30' coro=<HTTP1ServerConnection._server_request_loop() running at C:\Users\maryo\Desktop\python\jpnb\lib\site-packages\tornado\http1connection.py:840> cb=[IOLoop.add_future.<locals>.<lambda>() at C:\Users\maryo\Desktop\python\jpnb\lib\site-packages\tornado\ioloop.py:688]> while another task <Task pending name='Task-40' coro=<MappingKernelManager.start_kernel() running at C:\Users\maryo\Desktop\python\jpnb\lib\site-packages\notebook\services\kernels\kernelmanager.py:176> cb=[IOLoop.add_future.<locals>.<lambda>() at C:\Users\maryo\Desktop\python\jpnb\lib\site-packages\tornado\ioloop.py:688]> is being executed.
C:\Users\maryo\Desktop\python\jpnb\lib\site-packages\jupyter_client\ioloop\manager.py:9: RuntimeWarning: coroutine 'RequestHandler._execute' was never awaited
  from .restarter import AsyncIOLoopKernelRestarter
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
ERROR:asyncio:Task was destroyed but it is pending!
task: <Task pending name='Task-41' coro=<RequestHandler._execute() running at C:\Users\maryo\Desktop\python\jpnb\lib\site-packages\tornado\web.py:1660> cb=[_HandlerDelegate.execute.<locals>.<lambda>() at C:\Users\maryo\Desktop\python\jpnb\lib\site-packages\tornado\web.py:2326]>
1

3 Answers 3

17

On the bright side, this issue can be avoided by configuring Notebook to run with its AsyncMappingKernelManager instead - which introduces a full async stack

This method is not a permanent method every time you open Jupyter notebook you need to add these settings

jupyter notebook --NotebookApp.kernel_manager_class=notebook.services.kernels.kernelmanager.AsyncMappingKernelManager

or

This method is a permanent method

Step 1

run

jupyter notebook --generate-config

This will create jupyter_notebook_config.py in your Jupyter folder. The Jupyter folder is in your home directory, ~/.jupyter

Step 2

find these two lines in that folder

## The kernel manager class to use.
#  Default: 'notebook.services.kernels.kernelmanager.MappingKernelManager'

under that line add this line

c.NotebookApp.kernel_manager_class = 'notebook.services.kernels.kernelmanager.AsyncMappingKernelManager'

like this

## The kernel manager class to use.
#  Default: 'notebook.services.kernels.kernelmanager.MappingKernelManager'
#  c.NotebookApp.kernel_manager_class = 'notebook.services.kernels.kernelmanager.MappingKernelManager'
c.NotebookApp.kernel_manager_class = 'notebook.services.kernels.kernelmanager.AsyncMappingKernelManager'

Save and run jupyter notebook as normal

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

2 Comments

If you get The 'kernel_manager_class' trait of <notebook.notebookapp.NotebookApp object at 0x7f0a210acc88> instance must be a type, but 'notebook.services.kernels.kernelmanager.AsyncMappingKernelManager' could not be imported, make sure you've installed jupyter within the environment you're trying to launch a notebook from.
Thanks, that resolved my problem, struggled with that whole day
4

The suggested fix by Dumidu Parmith answer does not work for me due to

The 'kernel_manager_class' trait of <notebook.notebookapp.NotebookApp object at 0x7f0a210acc88> instance must be a type, but 'notebook.services.kernels.kernelmanager.AsyncMappingKernelManager' could not be imported

as mentioned in the comments to his answer.

As mentioned in the corresponding github issue installing jupyter_client<7 solved the issue for me.

So in case of conda, do

conda install 'jupyter_client<7'

and no configuration change is required. This installed version 6.1.2 in my case.

1 Comment

If one has the jupyter-console package installed, there will be a dependency conflict after downgrading jupyter-client. Above jupyter-console==6.4.2, jupyter-console requires jupyter-client>=7.0.0. So first, one has to downgrade to jupyter-console==6.4.2 and then downgrade to jupyter-client<7.0.0.
0

if you using anaconda, you try "pip install jupyter", instead of "conda install jupyter".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.