简体   繁体   中英

Cannot connect to Jupyter Notebook

My environment:

Windows 10 Professional Python 3.7.2 virtualenv 16.4.3

I created a new virtual environment with D:\Python37\Scripts\virualenv env

Then I activated the virtual environment with env\Scripts\activate

Then I installed jupyter with pip install --upgrade jupyter

Finally, I started jupyter with jupyter notebook

Everything starts up fine, and I create a new Python 3 notebook. Unfortunately, the notebook never connects to the server. I get the following error message in powershell

Replacing stale connection: (token)

In the browser, I get the following error message:

"A connection to the notebook server could not be established. The notebook will continue trying to reconnect. Check your network connection or notebook server configuration."

My two prior virtual environments (with Jupyter) work fine. I've deleted.ipython,.jupyter, AppData\Roaming\jupyter, without any luck.

I've cleared cookies from my browser and have tried a different browser. Nothing works.

I've created two other virtual environments before, and both of those still work.

All jupyter notebooks in the two working environments start up as untrusted, whereas the new environment starts up as trusted. I'm guessing that I clicked on something and now the notebook is looking to start up in a trusted fashion - which may require HTTPS.

Where do I look to fix this problem?

This appears to be a tornado issue. I found clues here.

  1. Jupyter no connection to server
  2. Jupyter kernel not connecting

I looked at the version of tornado (from the above links) in an environment that was working. It turns out that the version was 5.1.1 .

I looked at the version of tornado in an environment that was NOT working. It turns out that the version was 6.0 .

I downgraded the version of tornado in my non-working environment to 5.1.1 with the following command.

pip install --upgrade tornado==5.1.1

And now the non-working environment works

Anaconda is pretty good at handling any dependencies.I just tried this using Anaconda in the terminal:

 # see current envs conda info -e # make new environment, feel free to add your version of python with python=3.7 handle conda create -n test activate test conda list #This should appear empty conda install jupyter #y to install everything. jupyter notebook #launch jupyter notebook

Mine comes up as 'trusted'. The method above may not necessarily be the most minimalist way of doing things, but at least nothing breaks and you're up in running in no time. I'm using conda version: 4.6.2

Since this is one of the top answers to a Google search on the error:

" A connection to the notebook server could not be established. The notebook will continue trying to reconnect. Check your network connection or notebook server configuration. "

This might also have nothing to do with any install or library.
It may just be a proxy setting in your browser or on your system directly.
One solution may be to deactivate the proxy or add an exception to Jupyter's URI.

In my case, the situation was different. It was a browser caching issue, ie, I would call jupyter-lab using a batch script and it would just open a tab. Closing all explicitly tabs and then the browser worked me.

If there was an old instance of another disconnected jupyter-lab, it would somehow not establish a proper connection.

This solution work for me:

 pip uninstall Pyzmq pip install Pyzmq==19.0.2

Using pip to install some packages resulted in confusing the jupyter installation. So you can uninstall the packages installed with pip, disable the jupyter_contrib_nbextensions, then try to use conda install as possible.

 jupyter labextension disable my-extension

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM