5

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.

3 Answers3

16

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
Fouad Selmane
  • 378
  • 2
  • 11
5

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
pastaleg
  • 1,782
  • 2
  • 17
  • 23
  • sorry to revive it, but where exactly should I set it? i'm having same issue but i can't upgrade to 3.6.1 due to my project limitations, so i need to stick with this workaround – Emerson Oliveira Jan 25 '21 at 15:43
0

I got this error in CONDA environment:

  1. Had to uninstall the package like this:

conda remove -n pyspark_env prompt_toolkit

  1. Installed again as mentioned here:

conda install -c https://conda.anaconda.org/conda-forge prompt_toolkit

Python 3.7, prompt_toolkit - 3.0.2, November 2021

pnv
  • 1,437
  • 3
  • 23
  • 52