简体   繁体   English

无法连接到 Jupyter Notebook

[英]Cannot connect to Jupyter Notebook

My environment:我的环境:

Windows 10 Professional Python 3.7.2 virtualenv 16.4.3 Windows 10 专业 Python 3.7.2 virtualenv 16.4.3

I created a new virtual environment with D:\Python37\Scripts\virualenv env我用 D:\Python37\Scripts\virualenv env 创建了一个新的虚拟环境

Then I activated the virtual environment with env\Scripts\activate然后我用 env\Scripts\activate 激活了虚拟环境

Then I installed jupyter with pip install --upgrade jupyter然后我用 pip install --upgrade jupyter 安装了jupyter

Finally, I started jupyter with jupyter notebook最后,我用 jupyter notebook 开始了 jupyter

Everything starts up fine, and I create a new Python 3 notebook.一切正常,我创建了一个新的 Python 3 笔记本。 Unfortunately, the notebook never connects to the server.不幸的是,笔记本永远不会连接到服务器。 I get the following error message in powershell我在 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.我之前的两个虚拟环境(使用 Jupyter)运行良好。 I've deleted.ipython,.jupyter, AppData\Roaming\jupyter, without any luck.我已经删除了.ipython、.jupyter、AppData\Roaming\jupyter,没有任何运气。

I've cleared cookies from my browser and have tried a different browser.我已经从浏览器中清除了 cookies 并尝试了其他浏览器。 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.两个工作环境中的所有 jupyter notebook 都以不受信任的方式启动,而新环境以受信任的方式启动。 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.我猜我点击了一些东西,现在笔记本正在寻找以一种受信任的方式启动 - 这可能需要 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 Jupyter没有连接到服务器
  2. Jupyter kernel not connecting Jupyter kernel 未连接

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 .原来版本是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 .原来版本是6.0

I downgraded the version of tornado in my non-working environment to 5.1.1 with the following command.我使用以下命令将非工作环境中的 tornado 版本降级为 5.1.1。

pip install --upgrade tornado==5.1.1 pip 安装--升级龙卷风==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: Anaconda 非常擅长处理任何依赖项。我刚刚在终端中使用 Anaconda 进行了尝试:

 # 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我正在使用conda version: 4.6.2

Since this is one of the top answers to a Google search on the error:由于这是 Google 搜索错误的最佳答案之一:

" 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.一种解决方案可能是停用代理或向 Jupyter 的 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.这是一个浏览器缓存问题,即我会使用批处理脚本调用 jupyter-lab,它只会打开一个选项卡。 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.如果有另一个断开连接的 jupyter-lab 的旧实例,它将以某种方式无法建立正确的连接。

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.使用 pip 安装一些包会导致 jupyter 安装混乱。 So you can uninstall the packages installed with pip, disable the jupyter_contrib_nbextensions, then try to use conda install as possible.因此,您可以卸载使用 pip 安装的软件包,禁用 jupyter_contrib_nbextensions,然后尽可能使用 conda install。

 jupyter labextension disable my-extension

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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