19

I've tried installing jupyter notebook using pip3 install jupyter. Every time i launch a new jupyter notebook, the notebook is unable to connect to the kernel. See screenshot below Attaching my requirements.txt file, also i'm on Python version 3.6.8. Jupyter version is 4.4.0 with notebook version 5.7.4.

Where did i go wrong here and how can i fix this? Thanks!

attrs==18.2.0
backcall==0.1.0
bleach==3.1.0
colorama==0.4.1
cycler==0.10.0
decorator==4.3.2
defusedxml==0.5.0
entrypoints==0.3
ipykernel==5.1.0
ipython==7.3.0
ipython-genutils==0.2.0
ipywidgets==7.4.2
jedi==0.13.3
Jinja2==2.10
jsonschema==3.0.1
jupyter==1.0.0
jupyter-client==5.2.4
jupyter-console==6.0.0
jupyter-core==4.4.0
kiwisolver==1.0.1
MarkupSafe==1.1.1
matplotlib==3.0.3
mistune==0.8.4
nbconvert==5.4.1
nbformat==4.4.0
notebook==5.7.4
numpy==1.16.2
pandas==0.24.1
pandocfilters==1.4.2
parso==0.3.4
pickleshare==0.7.5
prometheus-client==0.6.0
prompt-toolkit==2.0.9
Pygments==2.3.1
pyparsing==2.3.1
pyrsistent==0.14.11
python-dateutil==2.8.0
pytz==2018.9
pywinpty==0.5.5
pyzmq==18.0.0
qtconsole==4.4.3
scikit-learn==0.20.3
scipy==1.2.1
seaborn==0.9.0
Send2Trash==1.5.0
six==1.12.0
sklearn==0.0
terminado==0.8.1
testpath==0.4.2
tornado==6.0
traitlets==4.3.2
wcwidth==0.1.7
webencodings==0.5.1
widgetsnbextension==3.4.2

Example

enter image description here

Davis Vickers
  • 191
  • 1
  • 1
  • 5

22 Answers22

31

There is a likelihood that you've updated Tornado to 6.0.0 recently. Try reinstalling it to version 5.1.1. It just helped me. Lost 1 hour of precious Saturday time on this.

  • 1
    Thanks, i checked and it looks like Tornado 6.0 came by default when did a pip install jupyter. I was able to uninstall, but i'm not able to do a pip install tornado 5.1.1. Any suggestions? It comes back and says could not find a version that satisfies the requirement 5.1.1. – Davis Vickers Mar 03 '19 at 00:41
  • 3
    Ah, nevermind. I was using wrong syntax. i used pip install tornado==5.1.1 and wala! Now i can connect to jupyter notebook again. Is this a bug on tornado 6.0? Just seems weird that jupyter won't work with tornado 6.0 and it's installed by default. – Davis Vickers Mar 03 '19 at 03:26
  • Glad we could all figure it out! Thanks to @Elena for discovering this issue. Just for further documentation, i found this is a common issue many people are reporting recently. https://github.com/jupyter/jupyter/issues/401 – Davis Vickers Mar 04 '19 at 03:29
  • @DavisVickers glad to hear it helped. For me it's not clear if this bug is on tornado or jupyter side. What I know is that the issue appeared as soon as I had updated tornado with the latest version. – Elena Yukhymenko Mar 04 '19 at 14:28
  • After installing version 5.1.1 I have this error `notebook 6.4.4 requires tornado>=6.1, but you have tornado 5.1.1 which is incompatible` – Florent Oct 08 '21 at 09:02
  • 2
    Using tornado==5.1.1 installed by conda did not solve the issue for me though. – Magnus Oct 14 '21 at 10:59
  • I have experienced the same problem with Dockerised JupyterLab. The "old version" (tag=`hub-1.5.0`) works flawlessly. The "newer" versions (tag=`hub-2.2.2` or `hub-2.3.1`) cannot connect to the kernel. Has nothing to do with `tornado`, I am sure. – András Aszódi Jun 15 '22 at 15:55
9

Create a conda environment using:

conda create -n my_env python=3

Activate the environment using:

source activate my_env

Install the ipykernel using:

conda install ipykernel

ipython kernel install --name my_env --user

Now open the jupyter and select the "my_env" from Kernel option. ( path : jupyter -> kernel -> change kernel -> my_env )

5

In my case, I just updated my jupyter and it worked.

CKM
  • 1,911
  • 2
  • 23
  • 30
5

That worked for me under Python 3.7.

pip3 install tornado==5.1.1
pip3 install notebook==5.7.4
Florent
  • 1,791
  • 22
  • 40
4

If the above does not work for you then this is highly recommended.

I had the same issue where the kernel would simply not connect. Tried every solution, still no connection.

In the end I noticed some Value Error Exceptions being raised in the console where I started the notebook client. The source of these exceptions was another python script in the same folder as the notebook.

delete all the python files in the same directory where notebook is installed or move them to some other folder. Fixed the notebook

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
delx
  • 41
  • 1
1

Just update the notebook, should work

1

I got this error:

from prompt_toolkit.eventloop import generator_to_async_generator
ImportError: cannot import name 'generator_to_async_generator' from 'prompt_toolkit.eventloop' (/Users/danielmlow/miniconda3/envs/pydra/lib/python3.7/site-packages/prompt_toolkit/eventloop/__init__.py)

So I upgraded prompt_toolkit:

pip install prompt_toolkit==3.0.
Daniel Low
  • 56
  • 3
1

My approach is similar to @AzizNal and @delx's answer.

I tracked my particular manifestation of this problem to the following:

  • I had a bunch of miscellaneous statements that I wanted to keep, and saved these in a file ./myworkingdirectory/random.py.

  • Any notebooks I attempted to open in the same directory as where this file was had trouble connecting to the kernel.

    (Likewise, any Spyder environment opened with a working direction of myworkingdirectory was crashing out and couldn't connect to a kernel)

  • Closer inspection of the error told me that numpy: cannot import name SystemRandom.

Given the above, I think this random.py of mine was conflicting with some other random.py. Removing or renaming the file solved the problem.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
simon
  • 13
  • 5
  • I had a similar problem. My case is I have a file named 'email.py' in the same folder of my '.ipynb' file. Since 'email' is a standard module, so I need to name my 'email.py' as another name, such as 'play_email.py', as long as the new name is different from any standard module name. The detail please refer to [https://groups.google.com/g/jupyter/c/TZwqNstDBRs](https://groups.google.com/g/jupyter/c/TZwqNstDBRs). – Ian Nov 04 '21 at 03:13
1

In my case, I created a virtual environment named "DL", but the notebook that should have run under this environment did not, so I uninstalled it from the notebook and installed it again with the commands:

jupyter kernelspec uninstall DL

python -m ipykernel install --user --name=DL

So, when I opened the Jupyter notebook, it connected with the DL kernel as before.

cgironda
  • 21
  • 5
1

I have found this same issue, and identified it only happens with Chrome standard browser. Incognito Chrome or Firefox does not have the same issue of ipykernel not connecting.

For now I open jupyter in firefox using the following command:

jupyter lab --browser Firefox

Not sure what the difference is with the browsers, but recently I have had an issue of not being able to access local files from chrome, so will look into this issue and see if that resolves it for Chrome standard browser.

0

I simply just restarted the Anaconda program and opened a new Python 3 notebook, and Jupyter could connect. :)

0

I had the same issue where the kernel would simply not connect. Tried every solution, still no connection.

In the end I noticed some ValueError Exceptions being raised in the console where I started the jupyter client. The source of these exceptions was another python script in the same folder as the notebook.

Fixed the script. Fixed the notebook.

aziznal
  • 11
  • 3
0

I experienced a similar issue on my old PC converted into a Ubuntu 20.04 server, with Jupyterlab running under Jupyterhub. The issue appeared after installing Jupytext with the following command:

python3 -m pip install jupytext --upgrade

which non only installed Jupytext but also upgraded my system to Jupyterlab 2.2.9 and Jupyterhub 1.2.2 (among other packages updates).

After that, running a cell containing the simple code:

3 * 4

under any python 3.6 kernel or even R 3.6 or 4.0 kernel left me with the status message:

Kernel xxx connecting...

but never completing the connection nor the simple computation.

Neither re-installing Tornado to version 5.1.1., nor reinstalling ipywidgets, succeeded in solving the issue.

But finally downgrading Jupyterlab and Jupyterhub to (approximately) the original version numbers worked for me:

python3 -m pip install wheel jupyterhub==1.1.0 jupyterlab==2.1.0 ipywidgets

According to the command outputs, the following packages versions were actually applied:

Installing collected packages: wheel, jupyterhub
  Attempting uninstall: wheel
    Found existing installation: wheel 0.34.2
    Uninstalling wheel-0.34.2:
      Successfully uninstalled wheel-0.34.2
  Attempting uninstall: jupyterhub
    Found existing installation: jupyterhub 1.1.0
    Uninstalling jupyterhub-1.1.0:
      Successfully uninstalled jupyterhub-1.1.0
Successfully installed jupyterhub-1.2.2 wheel-0.36.1

And after restarting jupyterhub, all my kernels were working again.

jimbod119
  • 2,871
  • 1
  • 6
  • 11
0

pip install jupytext --upgrade this work for me.

Abdu
  • 1
  • 2
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – no ai please Nov 21 '21 at 05:30
0

I had a similar issue using jupyter-lab. It would not connect to a kernel containing a virtual environment with python 3.9.

What worked for me was to UPDATE tornado. By default when running pip install ipykernel tornado 6.1 is installed. I uninstalled it with pip uninstall tornado then pip install tornado, which installed 6.2, and the issue was solved.

keloks
  • 1
  • 1
0

In my case just open give two minutes.Then open jupyter notebook using anaconda navigator. This time it will work totally fine whether you open it from Prompt or Navigator

0

It's because of incompatible package versions.

Try to:

pip uninstall notebook -y

And then:

pip install notebook

0

I also had this problem, with kernel failing to connect, when I run this command:

jupyter kernelspec list

Available kernels: python3
C:\Users\jijon\AppData\Roaming\Python\Python38\site-packages\ipykernel\resources

I discovered the ipykernel needs to be installed, as given by this link:

https://ipython.readthedocs.io/en/stable/install/kernel_install.html

So I ran this command from the command prompt:

python -m ipykernel install --user

After that, here's what my python3 kernel changed to:

jupyter kernelspec list

Available kernels: python3
C:\Users\jijon\AppData\Roaming\jupyter\kernels\python3

And that fixed it!

alea
  • 980
  • 1
  • 13
  • 18
-1

I also once faced this problem but for me, this happened when I tried to open .ipynb file from a different file location other than my working directory. But this was solved by moving the required file to my working directory.

So, for your issue just make sure whether your launched new notebook is in your working directory or not.

-1

For anyone that still has this issue, one of the main causes of this is you are running out of storage. Try deleting some files to make some room.

Nathan Montanez
  • 9
  • 1
  • 1
  • 2
-1

Just upgrade your tornado version by using this command in conda environment -

conda install -c anaconda tornado

Sahana M
  • 485
  • 6
  • 4
-2

for linux and windows:

     just install ipython kernel

           "python3 -m pip install ipykernel"

           "python3 -m ipykernel install --user"

      then restart jupyter notebook that's it
hemanth
  • 1
  • 1