Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel crashes with ModuleNotFoundError on 'prompt_toolkit.formatted_text' #4050

Closed
katcosgrove opened this issue Sep 28, 2018 · 36 comments
Closed

Comments

@katcosgrove
Copy link

katcosgrove commented Sep 28, 2018

With a fresh install of Jupyter in a clean pipenv or virtualenv, a new notebook crashes immediately upon launch with the following in terminal:

[I 13:39:55.748 NotebookApp] KernelRestarter: restarting kernel (4/5), new random ports
Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/kat/Projects/jupyter_bug/ENV/lib/python3.7/site-packages/ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "/Users/kat/Projects/jupyter_bug/ENV/lib/python3.7/site-packages/ipykernel/__init__.py", line 2, in <module>
    from .connect import *
  File "/Users/kat/Projects/jupyter_bug/ENV/lib/python3.7/site-packages/ipykernel/connect.py", line 13, in <module>
    from IPython.core.profiledir import ProfileDir
  File "/Users/kat/Projects/jupyter_bug/ENV/lib/python3.7/site-packages/IPython/__init__.py", line 55, in <module>
    from .terminal.embed import embed
  File "/Users/kat/Projects/jupyter_bug/ENV/lib/python3.7/site-packages/IPython/terminal/embed.py", line 16, in <module>
    from IPython.terminal.interactiveshell import TerminalInteractiveShell
  File "/Users/kat/Projects/jupyter_bug/ENV/lib/python3.7/site-packages/IPython/terminal/interactiveshell.py", line 20, in <module>
    from prompt_toolkit.formatted_text import PygmentsTokens
ModuleNotFoundError: No module named 'prompt_toolkit.formatted_text'
[W 13:39:58.759 NotebookApp] KernelRestarter: restart failed
[W 13:39:58.760 NotebookApp] Kernel d6c405e3-6b72-4be9-93fd-f44aecc78576 died, removing from map.

Originally seen on an Ubuntu 18.04 machine using Python 3.7 and recreated on Mac OS Sierra and High Sierra with 3.7, as well as Ubuntu 16.04 with 2.7 and then 3.6. Four separate machines.

@bhanuvrat
Copy link

bhanuvrat commented Sep 29, 2018

This came up during installation and later resulted in the error mentioned by OP.

ipython` 7.0.1 has requirement prompt-toolkit<2.1.0,>=2.0.0, but you'll have prompt-toolkit 1.0.15 which is incompatible

installing latest version of prompt-toolkit==2.0.4 resulted in

jupyter-console 5.2.0 has requirement prompt-toolkit<2.0.0,>=1.0.0, but you'll have prompt-toolkit 2.0.4 which is incompatible

so it seems that ipython and jupyter-console have conflicting versions of prompt-toolkit as dependency.


installing with pipenv gives this error:

Adding jupyter to Pipfile's [packages]...
Pipfile.lock not found, creating...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...

Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
  You can use $ pipenv install --skip-lock to bypass this mechanism, then run $ pipenv graph to inspect the situation.
  Hint: try $ pipenv lock --pre if it is a pre-release dependency.
Could not find a version that matches prompt-toolkit<2.0.0,<2.1.0,==1.0.15,>=1.0.0,>=2.0.0
Tried: 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.8, 0.9, 0.10, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 0.23, 0.25, 0.26, 0.28, 0.30, 0.31, 0.32, 0.32, 0.32, 0.33, 0.33, 0.33, 0.34, 0.34, 0.34, 0.35, 0.35, 0.35, 0.36, 0.36, 0.36, 0.37, 0.37, 0.37, 0.38, 0.38, 0.38, 0.39, 0.39, 0.39, 0.40, 0.40, 0.40, 0.41, 0.41, 0.41, 0.42, 0.42, 0.42, 0.43, 0.43, 0.43, 0.44, 0.44, 0.44, 0.45, 0.45, 0.45, 0.46, 0.46, 0.46, 0.47, 0.47, 0.47, 0.48, 0.48, 0.48, 0.49, 0.49, 0.49, 0.50, 0.50, 0.50, 0.51, 0.51, 0.51, 0.52, 0.52, 0.52, 0.53, 0.53, 0.53, 0.54, 0.54, 0.54, 0.55, 0.55, 0.55, 0.56, 0.56, 0.56, 0.57, 0.57, 0.57, 0.58, 0.58, 0.58, 0.59, 0.59, 0.59, 0.60, 0.60, 0.60, 1.0.0, 1.0.0, 1.0.0, 1.0.1, 1.0.1, 1.0.1, 1.0.2, 1.0.2, 1.0.2, 1.0.3, 1.0.3, 1.0.3, 1.0.4, 1.0.4, 1.0.4, 1.0.5, 1.0.5, 1.0.5, 1.0.6, 1.0.6, 1.0.6, 1.0.7, 1.0.7, 1.0.7, 1.0.8, 1.0.8, 1.0.8, 1.0.9, 1.0.9, 1.0.9, 1.0.10, 1.0.10, 1.0.10, 1.0.13, 1.0.13, 1.0.13, 1.0.14, 1.0.14, 1.0.14, 1.0.15, 1.0.15, 1.0.15, 2.0.1, 2.0.1, 2.0.1, 2.0.2, 2.0.2, 2.0.2, 2.0.3, 2.0.3, 2.0.3, 2.0.4, 2.0.4, 2.0.4
There are incompatible versions in the resolved dependencies.

@bhanuvrat
Copy link

seems like it is being fixed here nengo/nengo-dl@f71bcef

@sirusss
Copy link

sirusss commented Sep 29, 2018

As a temporary workaround, this will fix it:
pip install 'ipykernel<5.0.0'

@s3afroze
Copy link

As a temporary workaround, this will fix it:
pip install 'ipykernel<5.0.0'

Have been trying to fix for hours.
Thank you,

@Carreau
Copy link
Member

Carreau commented Oct 1, 2018

pip install 'ipykernel<5.0.0'

It seem extremely unlikely this was the problem. IPykernel does not rely on prompt_toolkit, and IPykernel<5 with IPython>7 will still break jupyter.

For those of you who tried and for who this fixes things with version of IPython is now installed ?

@s-weigand
Copy link

s-weigand commented Oct 1, 2018

The jupyter-console master also supports prompt-toolkit>2, so instead of downgrading ipython, upgrading jupyter-console should work als well (tested it in a fresh conda env after the ipython 7.0 release).
So the other temporary workaround (untill the next version of jupyter-console is on PyPi), that will fix it is:
pip install git+https://github.com/jupyter/jupyter_console

See jupyter_console #167, for updates on the release.

@Carreau
Copy link
Member

Carreau commented Oct 1, 2018

Sure, but I dont' think everyone should run for master.

It just make no sens that downgrading ipykernel fixes things. It must be a fluke.
The only change in files that trigger above error was a typo in a docstring.

@miker985
Copy link

miker985 commented Oct 2, 2018

pip install 'ipykernel<5.0.0'

This fixed the problem for me such that the Kernel would start and I could use my notebook.

@gonzales-edwin
Copy link

As a temporary workaround, this will fix it:
pip install 'ipykernel<5.0.0'

Thank you, this fixed my problem also. I was able to open up notebooks but the cells would not run.

@dapperfu
Copy link

dapperfu commented Oct 2, 2018

Using jupyter notebooks, if I just specify ipykernel with 'jupyter' as a requirement I still get this error:

jupyter-console 5.2.0 has requirement prompt-toolkit<2.0.0,>=1.0.0, but you'll have prompt-toolkit 2.0.5 which is incompatible.

The minimal requirements.txt that gives me working notebook is:

ipykernel<5.0.0
notebook

pip figures it out from there.

If you add ipython

same error ipython 7.0.1 has requirement prompt-toolkit<2.1.0,>=2.0.0, but you'll have prompt-toolkit 1.0.15 which is incompatible.

So you need ipython<7.0.0 as well if you have ipython specified.

@gronki
Copy link

gronki commented Oct 2, 2018

I confirm below works for me at the moment (ipykernel<5.0.0 alone was not enough):

pip3 install jupyter 'ipykernel<5.0.0' 'ipython<7.0.0'

mstefferson added a commit to mstefferson/Canopy that referenced this issue Oct 2, 2018
@KTM-300
Copy link

KTM-300 commented Oct 4, 2018

I have the same error as indicated above.

If I try pip install 'ipykernel<5.0.0' command in my command prompt of Windows 10, I get the following error

The system cannot find the file specified.

Please can you let this newbie know how to rectify this error?

@s-weigand
Copy link

since there is a new release of jupyter_console the following command should fix the problem if its allready there and if not it shouldn't appear anymore:
pip install -U jupyter_console
@KTM-300 does your system know about pip (does pip --version work)?
If not you can add the path of your python installation to the PATH variable.

@KTM-300
Copy link

KTM-300 commented Oct 4, 2018

Thanks for helping.

Yes, pip --version works.

I managed to get around the problem with the answer from https://stackoverflow.com/questions/52551878/problems-upgrading-ipython-prompt-toolkit-incompatibilities

@tpanza
Copy link

tpanza commented Oct 18, 2018

Confirmed that pip install -U jupyter_console fixes this.

In particular, this problem started happening in my environment with prompt-toolkit-1.0.15. For what it's worth, my environment initially had prompt-toolkit-2.0.5, but then an install of py2neo into my environment forced a downgrade of prompt-toolkit to 1.0.15.

So, this may happen if the installation of a new package sneaks in a downgrade of prompt-toolkit down to 1.x.

@echocherish
Copy link

You can try to upgrade jupyter-conslole 's version, then promblems are fixed.

@tonianev
Copy link

As a temporary workaround, this will fix it:
pip install 'ipykernel<5.0.0'

Thank you so much!

@etoatibm
Copy link

Hi

pip install -U jupyter_console

helped me out.

JanuszL added a commit to NVIDIA/DALI that referenced this issue Dec 12, 2019
- when tensorflow-gpu v1.15.0 is installed in the conda environment
  some strange dependency leads to `ModuleNotFoundError: No module
  named 'prompt_toolkit.formatted_text'` error
- according to jupyter/notebook#4050 installing
  `ipykernel<5.0.0 ipython<7.0.0` helps
- fixes cupy version to 6.6.0 as this the last one supporting python 2.7

Signed-off-by: Janusz Lisiecki <[email protected]>
klecki pushed a commit to NVIDIA/DALI that referenced this issue Dec 12, 2019
- when tensorflow-gpu v1.15.0 is installed in the conda environment
  some strange dependency leads to `ModuleNotFoundError: No module
  named 'prompt_toolkit.formatted_text'` error
- according to jupyter/notebook#4050 installing
  `ipykernel<5.0.0 ipython<7.0.0` helps
- fixes cupy version to 6.6.0 as this the last one supporting python 2.7

Signed-off-by: Janusz Lisiecki <[email protected]>
@rambail
Copy link

rambail commented Dec 31, 2019

pip install -U jupyter_console

+1

@diponkor-bala
Copy link

diponkor-bala commented Jan 6, 2020

pip install -U jupyter_console
is working properly

@PraveenKumar-Rajendran
Copy link

As a temporary workaround, this will fix it:
pip install 'ipykernel<5.0.0'

Thank you so much, I almost took a day to solve this.

@remborg
Copy link

remborg commented Jun 11, 2020

If I try pip install 'ipykernel<5.0.0' command in my command prompt of Windows 10, I get the following error

The system cannot find the file specified.

I had to replace the single quotes to double quotes to get the command to work:
pip install "ipykernel<5.0.0"

@kevin-bates
Copy link
Member

(From #5024 (comment)) Rather than downgrade ipykernel and IPython, especially given the timeframe of those initial suggestions (which may have been correct at the time), I would first try ensuring that you're running the latest versions of each and upgrade if not.

Also, since IPython appears to be sensitive to the version of prompt_toolkit, I would recommend checking prompt_toolkit's version as well.

If someone finds this "upgrade" approach successful, could you please add a comment? This will allow future incidents to be forward-moving rather than not. Thank you.

@benbwf
Copy link

benbwf commented Jul 6, 2020

I confirm below works for me at the moment (ipykernel<5.0.0 alone was not enough):

pip3 install jupyter 'ipykernel<5.0.0' 'ipython<7.0.0'

Thanks @gronki

conda install ipykernel'<5.0.0' ipython'<7.0.0' worked for me.
like you, just ipykernel'<5.0.0' wasn't enough.

@beniroquai
Copy link

@kevin-bates This worked for me indeed:

pip install prompt_toolkit --force-reinstall

Thanks!

@julianschoep
Copy link

julianschoep commented Aug 4, 2020

pip install ipython==7 prompt-toolkit==2.0.10 jupyter-console==6.0.0
worked for me

@ShengHow95
Copy link

pip install ipython==7 prompt-toolkit==2.0.10 jupyter-console==6.0.0
worked for me

This worked for me. Thanks!

@mahamatnoumai
Copy link

pip install ipython==7 prompt-toolkit==2.0.10 jupyter-console==6.0.0
worked for me

Hey it's worked for me too. it's saved my day. thanks

@lchapo
Copy link

lchapo commented Sep 10, 2020

conda update jupyter will also get compatible package versions for anyone using conda

@stas00
Copy link

stas00 commented Nov 14, 2020

And sometimes some package forces the old prompt_toolkit version on you, as is the case with wandb at the moment: wandb/wandb#1498

@Vivian12345
Copy link

If I try pip install 'ipykernel<5.0.0' command in my command prompt of Windows 10, I get the following error

The system cannot find the file specified.

I had to replace the single quotes to double quotes to get the command to work:
pip install "ipykernel<5.0.0"

Thanks a lot!
need to double quotes +1

@Vivian12345
Copy link

pip install ipython==7 prompt-toolkit==2.0.10 jupyter-console==6.0.0
worked for me

Thank you very much~
It works!

@ethanjyx
Copy link

As a temporary workaround, this will fix it: pip install 'ipykernel<5.0.0'

This worked for me... thanks!

@tonyfast
Copy link
Collaborator

This appears to be solved by updating IPython or ipykernel. Thanks for the discussion y'all. ❤️ Jupyter Triage Team

@ainunnawawi
Copy link

pip install ipykernel

@abaveja313
Copy link

pip install ipykernel

Worked for me

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests