Ipython: ImportError: cannot import name 'generator_to_async_generator'

Created on 25 Aug 2018  路  11Comments  路  Source: ipython/ipython

When I run Ipython on Ubuntu18.04,I got this ImportError.

Most helpful comment

As you suggested:

pip uninstall -y ipython prompt_toolkit
pip install ipython prompt_toolkit

fixed it for me on python-3.7.

Thank you.

All 11 comments

Can you past the full-error ?

This look like a function that appear in prompt_toolkit, so you likely have an incompatible version of prompt_tookit. Upgrade or downgrade to a matching version.

Closing for now, but feel free to comment if this need to be reopened.

@Carreau

Traceback (most recent call last):
  File "/home/qleegb/.local/lib/python3.6/site-packages/spyder/app/mainwindow.py", line 3181, in main
    mainwindow = run_spyder(app, options, args)
  File "/home/qleegb/.local/lib/python3.6/site-packages/spyder/app/mainwindow.py", line 3057, in run_spyder
    main.setup()
  File "/home/qleegb/.local/lib/python3.6/site-packages/spyder/app/mainwindow.py", line 896, in setup
    from spyder.plugins.ipythonconsole import IPythonConsole
  File "/home/qleegb/.local/lib/python3.6/site-packages/spyder/plugins/ipythonconsole.py", line 59, in <module>
    from spyder.widgets.ipythonconsole import ClientWidget
  File "/home/qleegb/.local/lib/python3.6/site-packages/spyder/widgets/ipythonconsole/__init__.py", line 12, in <module>
    from .debugging import DebuggingWidget
  File "/home/qleegb/.local/lib/python3.6/site-packages/spyder/widgets/ipythonconsole/debugging.py", line 17, in <module>
    from qtconsole.rich_jupyter_widget import RichJupyterWidget
  File "/home/qleegb/.local/lib/python3.6/site-packages/qtconsole/rich_jupyter_widget.py", line 14, in <module>
    from .jupyter_widget import JupyterWidget
  File "/home/qleegb/.local/lib/python3.6/site-packages/qtconsole/jupyter_widget.py", line 19, in <module>
    from IPython.lib.lexers import IPythonLexer, IPython3Lexer
  File "/home/qleegb/.local/lib/python3.6/site-packages/IPython/__init__.py", line 55, in <module>
    from .terminal.embed import embed
  File "/home/qleegb/.local/lib/python3.6/site-packages/IPython/terminal/embed.py", line 16, in <module>
    from IPython.terminal.interactiveshell import TerminalInteractiveShell
  File "/home/qleegb/.local/lib/python3.6/site-packages/IPython/terminal/interactiveshell.py", line 18, in <module>
    from prompt_toolkit.document import Document
  File "/home/qleegb/.local/lib/python3.6/site-packages/prompt_toolkit/__init__.py", line 16, in <module>
    from .interface import CommandLineInterface
  File "/home/qleegb/.local/lib/python3.6/site-packages/prompt_toolkit/interface.py", line 19, in <module>
    from .application import Application, AbortAction
  File "/home/qleegb/.local/lib/python3.6/site-packages/prompt_toolkit/application/__init__.py", line 2, in <module>
    from .application import Application
  File "/home/qleegb/.local/lib/python3.6/site-packages/prompt_toolkit/application/application.py", line 3, in <module>
    from prompt_toolkit.buffer import Buffer
  File "/home/qleegb/.local/lib/python3.6/site-packages/prompt_toolkit/buffer.py", line 9, in <module>
    from .completion import Completer, Completion, CompleteEvent
  File "/home/qleegb/.local/lib/python3.6/site-packages/prompt_toolkit/completion/__init__.py", line 2, in <module>
    from .base import Completion, Completer, ThreadedCompleter, DummyCompleter, DynamicCompleter, CompleteEvent, merge_completers, get_common_complete_suffix
  File "/home/qleegb/.local/lib/python3.6/site-packages/prompt_toolkit/completion/base.py", line 4, in <module>
    from prompt_toolkit.eventloop import generator_to_async_generator, AsyncGeneratorItem
ImportError: cannot import name 'generator_to_async_generator'

Successfully installed backcall-0.1.0 decorator-4.3.0 ipython-6.5.0 ipython-genutils-0.2.0 jedi-0.12.1 parso-0.3.1 pexpect-4.6.0 pickleshare-0.7.4 prompt-toolkit-2.0.4 ptyprocess-0.6.0 pygments-2.2.0 setuptools-40.2.0 simplegeneric-0.8.1 six-1.11.0 traitlets-4.3.2 wcwidth-0.1.7

This look like prompt_toolkit has been misinstalled. Remove it and reinstall it.
How did you install ? Pip ? Sudo (if you used sudo that might be why, never use sudo with pip)

What does

python -c 'import prompt_toolkit.eventloop; print(prompt_toolkit.eventloop.__file__)'

says ?

/home/qleegb/.local/lib/python3.6/site-packages/prompt_toolkit/eventloop/__init__.py

$ ipython3
Traceback (most recent call last):
File "/home/qleegb/.local/bin/ipython3", line 7, in
from IPython import start_ipython
File "/home/qleegb/.local/lib/python3.6/site-packages/IPython/__init__.py", line 55, in
from .terminal.embed import embed
File "/home/qleegb/.local/lib/python3.6/site-packages/IPython/terminal/embed.py", line 16, in
from IPython.terminal.interactiveshell import TerminalInteractiveShell
File "/home/qleegb/.local/lib/python3.6/site-packages/IPython/terminal/interactiveshell.py", line 22, in
from prompt_toolkit.shortcuts import create_prompt_application, create_eventloop, create_prompt_layout, create_output
ImportError: cannot import name 'create_prompt_application'

That is super weird.

Try to uninstall ipython & prompt toolkit. potentially do several pip uninstall to be sure you do not have multiple installs.

If this does not fix it I would try something like https://github.com/takluyver/damnpth , because it really looks like your system is finding 2 versions of Prompt_toolkit at the same time...

As you suggested:

pip uninstall -y ipython prompt_toolkit
pip install ipython prompt_toolkit

fixed it for me on python-3.7.

Thank you.

@Carreau Thank you your suggestion:
reinstall ipython & prompt toolkit

Thanks, that worked. Just in case others are in the same situation I was: I had to pip uninstall/install from within the troubled conda environment, even when launching jupyter from the base env.

In my case with python3.7, I uninstalled both ipython and prompt_toolkit as shown by @stas00 and just installed ipython so that it installs the compatible prompt_toolkit itself

pip uninstall -y ipython prompt_toolkit
pip install ipython
Was this page helpful?
0 / 5 - 0 ratings