Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot get Jupyter Notebook To Run - "Cannot Import Name AsyncGenerator"

Anyone have any suggestions on how to fix this problem? I am NOT using Anaconda. The version of Jupyter I have is 1.0.0.

Traceback (most recent call last):
  File "c:\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\python36\lib\site-packages\ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "c:\python36\lib\site-packages\ipykernel\__init__.py", line 2, in <module>
    from .connect import *
  File "c:\python36\lib\site-packages\ipykernel\connect.py", line 13, in <module>
    from IPython.core.profiledir import ProfileDir
  File "c:\python36\lib\site-packages\IPython\__init__.py", line 56, in <module>
    from .terminal.embed import embed
  File "c:\python36\lib\site-packages\IPython\terminal\embed.py", line 16, in <module>
    from IPython.terminal.interactiveshell import TerminalInteractiveShell
  File "c:\python36\lib\site-packages\IPython\terminal\interactiveshell.py", line 19, in <module>
    from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode
  File "c:\python36\lib\site-packages\prompt_toolkit\__init__.py", line 16, in <module>
    from .application import Application
  File "c:\python36\lib\site-packages\prompt_toolkit\application\__init__.py", line 1, in <module>
    from .application import Application
  File "c:\python36\lib\site-packages\prompt_toolkit\application\application.py", line 38, in <module>
    from prompt_toolkit.buffer import Buffer
  File "c:\python36\lib\site-packages\prompt_toolkit\buffer.py", line 28, in <module>
    from .application.current import get_app
  File "c:\python36\lib\site-packages\prompt_toolkit\application\current.py", line 8, in <module>
    from prompt_toolkit.eventloop.dummy_contextvars import ContextVar  # type: ignore
  File "c:\python36\lib\site-packages\prompt_toolkit\eventloop\__init__.py", line 1, in <module>
    from .async_generator import generator_to_async_generator
  File "c:\python36\lib\site-packages\prompt_toolkit\eventloop\async_generator.py", line 5, in <module>
    from typing import AsyncGenerator, Callable, Iterable, TypeVar, Union
ImportError: cannot import name 'AsyncGenerator'

Much thanks.

like image 687
we_are_all_in_this_together Avatar asked Dec 03 '22 09:12

we_are_all_in_this_together


2 Answers

The reason is that the version of prompt_toolkit does not match Python 3.6

The solution is to reduce the version

pip install --upgrade prompt-toolkit==2.0.1
like image 185
Fouad Selmane Avatar answered Jan 13 '23 11:01

Fouad Selmane


According to a Github issue related to the same error text: https://github.com/python/typing/issues/530, this is a bug that is fixed in Python 3.6.1.

Since you are using Python 3.6.0, you should upgrade your version to 3.6.1 or higher to fix the issue.

Alternatively, a workaraound is to set

if TYPE_CHECKING: from typing import AsyncGenerator
like image 20
pastaleg Avatar answered Jan 13 '23 11:01

pastaleg