Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jupyter ImportError: cannot import name 'create_prompt_application' ubuntu 18.04

I have installed jupypter on Ubuntu 18.04. when I try to open .ipynb file it says trying to connect to server and fails eventaully. When I looked at the console I saw the following error :

ImportError: cannot import name 'create_prompt_application' as follows

[I 14:37:41.311 NotebookApp] KernelRestarter: restarting kernel (4/5), new random ports
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "/usr/local/lib/python3.6/dist-packages/ipykernel/__init__.py", line 2, in <module>
    from .connect import *
  File "/usr/local/lib/python3.6/dist-packages/ipykernel/connect.py", line 13, in <module>
    from IPython.core.profiledir import ProfileDir
  File "/usr/lib/python3/dist-packages/IPython/__init__.py", line 49, in <module>
    from .terminal.embed import embed
  File "/usr/lib/python3/dist-packages/IPython/terminal/embed.py", line 18, in <module>
    from IPython.terminal.interactiveshell import TerminalInteractiveShell
  File "/usr/lib/python3/dist-packages/IPython/terminal/interactiveshell.py", line 20, in <module>
    from prompt_toolkit.shortcuts import create_prompt_application, create_eventloop, create_prompt_layout, create_output
ImportError: cannot import name 'create_prompt_application'
[W 14:37:44.322 NotebookApp] KernelRestarter: restart failed

Some posts related to IPyton are suggesting that prompt-toolkit should be downgraded. I run deptree to get dependency tree as follows, which shows that prompt-toolkit 2.0.9 is installed and required version for jupyter-console should be between 2.0.0 and 2.0.1

- jupyter-console [required: Any, installed: 6.0.0]
    - ipykernel [required: Any, installed: 5.1.0]
      - ipython [required: >=5.0.0, installed: 5.5.0]
        - pexpect [required: Any, installed: 4.2.1]
      - jupyter-client [required: Any, installed: 5.2.4]
        - jupyter-core [required: Any, installed: 4.4.0]
          - traitlets [required: Any, installed: 4.3.2]
        - python-dateutil [required: >=2.1, installed: 2.6.1]
        - pyzmq [required: >=13, installed: 18.0.1]
        - tornado [required: >=4.1, installed: 6.0.1]
        - traitlets [required: Any, installed: 4.3.2]
      - tornado [required: >=4.2, installed: 6.0.1]
      - traitlets [required: >=4.1.0, installed: 4.3.2]
    - ipython [required: Any, installed: 5.5.0]
      - pexpect [required: Any, installed: 4.2.1]
    - jupyter-client [required: Any, installed: 5.2.4]
      - jupyter-core [required: Any, installed: 4.4.0]
        - traitlets [required: Any, installed: 4.3.2]
      - python-dateutil [required: >=2.1, installed: 2.6.1]
      - pyzmq [required: >=13, installed: 18.0.1]
      - tornado [required: >=4.1, installed: 6.0.1]
      - traitlets [required: Any, installed: 4.3.2]
    - prompt-toolkit [required: >=2.0.0,<2.1.0, installed: 2.0.9]

Any thoughts on what could be wrong and what should I do? Thanks

like image 407
Amin Merati Avatar asked Mar 19 '19 14:03

Amin Merati


2 Answers

It is best to upgrade jupyter-console with this command:

pip3 install --upgrade --force jupyter-console

Then it will be compatible with later versions of prompt-toolkit.

More details in this github issue.

like image 113
Arjaan Buijk Avatar answered Nov 01 '22 21:11

Arjaan Buijk


sudo pip3 uninstall ipython

sudo pip3 install ipython

the error solved for me Try it out.

sudo pip3 install 'prompt-toolkit<2.1.0,>=2.0.0' --force-reinstall

like image 13
suraj kumar Avatar answered Nov 01 '22 21:11

suraj kumar