【问题标题】:Jupyter notebook: No connection to server because websocket connection failsJupyter notebook:没有连接到服务器,因为 websocket 连接失败
【发布时间】:2019-07-24 13:45:27
【问题描述】:

我刚刚在 Windows 10 中通过 pip(Python 版本为 3.7.2)安装了 Jupyter,通过调用 jupyter notebook 启动了 jupyter 服务器,在我的网络浏览器中创建了一个带有内核 python3 的新笔记本,但与内核的连接是从未实现。

命令行没有明显错误:

C:\Users\xxxx>jupyter notebook
[I 21:18:21.005 NotebookApp] Serving notebooks from local directory: C:\Users\xxxx
[I 21:18:21.005 NotebookApp] The Jupyter Notebook is running at:
[I 21:18:21.006 NotebookApp] http://localhost:8888/?token=5743fcbbc805efa4b36c983a7beb63b95cf922957378d64f
[I 21:18:21.007 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 21:18:21.087 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///C:/Users/xxxx/AppData/Roaming/jupyter/runtime/nbserver-18416-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=5743fcbbc805efa4b36c983a7beb63b95cf922957378d64f
[I 21:18:33.777 NotebookApp] Creating new notebook in
[I 21:18:35.512 NotebookApp] Kernel started: ab30c1b3-55d2-45e9-9f01-b4bfc077bb01
[I 21:18:36.883 NotebookApp] Adapting to protocol v5.1 for kernel ab30c1b3-55d2-45e9-9f01-b4bfc077bb01
c:\users\xxxx\appdata\local\programs\python\python37-32\lib\site-packages\notebook\base\zmqhandlers.py:284: RuntimeWarning: coroutine 'WebSocketHandler.get' was never awaited
  super(AuthenticatedZMQStreamHandler, self).get(*args, **kwargs)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
[W 21:18:37.912 NotebookApp] Replacing stale connection: ab30c1b3-55d2-45e9-9f01-b4bfc077bb01:397de5420f9e4bce82d95967bf5fa1eb
[W 21:19:14.026 NotebookApp] 404 GET /static/components/preact/preact.min.js.map (::1) 18.98ms referer=None
[W 21:19:14.040 NotebookApp] 404 GET /static/components/preact-compat/preact-compat.min.js.map (::1) 6.49ms referer=None
[W 21:19:14.050 NotebookApp] 404 GET /static/components/proptypes/index.js.map (::1) 15.99ms referer=None
[I 21:20:36.067 NotebookApp] Saving file at /Untitled1.ipynb
[W 21:22:40.052 NotebookApp] Replacing stale connection: ab30c1b3-55d2-45e9-9f01-b4bfc077bb01:397de5420f9e4bce82d95967bf5fa1eb

我尝试了所有 Chrome、Firefox 和 Microsoft Edge,但均未成功。我什至尝试过 PyCharm。

然后看了下浏览器的js控制台,好像问题是websocket连接失败:

menubar.js:277 actions jupyter-notebook:find-and-replace does not exist, still binding it in case it will be defined later...
MenuBar.bind_events @ menubar.js:277
utils.js:60 load_extensions Arguments(1)
bidi.js:19 Loaded moment locale en
utils.js:37 Loading extension: jupyter-js-widgets/extension
session.js:54 Session: kernel_created (003a523b-3d40-41ac-b65e-154db92d5528)
kernel.js:459 Starting WebSockets: ws://localhost:8888/api/kernels/f8809bf9-988f-4666-b183-e01bed63fa76
kernel.js:461 WebSocket connection to 'ws://localhost:8888/api/kernels/f8809bf9-988f-4666-b183-e01bed63fa76/channels?session_id=e49c21f065e64e7a89847a0859d689dd' failed: Error during WebSocket handshake: Unexpected response code: 200
Kernel.start_channels @ kernel.js:461
kernel.js:103 Kernel: kernel_disconnected (f8809bf9-988f-4666-b183-e01bed63fa76)
kernel.js:544 WebSocket connection failed:  ws://localhost:8888/api/kernels/f8809bf9-988f-4666-b183-e01bed63fa76 true
kernel.js:562 Connection lost, reconnecting in 1 seconds.
kernel.js:103 Kernel: kernel_reconnecting (f8809bf9-988f-4666-b183-e01bed63fa76)
kernel.js:459 Starting WebSockets: ws://localhost:8888/api/kernels/f8809bf9-988f-4666-b183-e01bed63fa76

这可能是什么原因?

【问题讨论】:

标签: python jupyter-notebook


【解决方案1】:

我遇到了同样的问题,按照这个 vvk2001github https://github.com/jupyter/notebook/issues/4399 为我修复了它。

卸载 tornado 6 并重新安装 tornado 5。

sudo pip3 uninstall tornado
sudo pip3 install tornado==5.1.1

@kaleo 也对@Jason Nichols 的类似问题给出了这个答案

【讨论】:

  • 昨天也浪费了时间,感谢您的解决方案。还决定我的 jhub 包将从现在开始在安装时记录一个带日期戳的 pip 冻结日志。
  • 遇到了同样的问题。这个解决方案对我有用。非常感谢!!
  • 谢谢!在过去的 5 个小时里,我一直在尝试解决这个问题。这个解决方案奏效了。
  • @NicoWheat .. 谢谢。我建议的唯一一项更改是使用sudo pip3 -y uninstall tornado,我们必须在其中执行一些脚本,而不必将 uninstall 命令的 y 作为输入。
  • 现在应该不需要降级了,升级notebook,nbconvert也可以
【解决方案2】:

Jupyter Notebook 5.7.5 更新应该可以解决 Tornado 6 的问题。请参阅 Jupyter 团队的 tweeted 公告和 github release tag

截至 2019 年 3 月 6 日,docsconda distribution 都处于待更改状态。不过你可以update using pip


从文档中升级:

> pip install notebook --upgrade

验证版本:

> pip --version

【讨论】:

  • 这对我有用。 [笔记本 5.7.0 / tornado 6.0.3 (ERR)] --> [笔记本 5.7.8 / tornado 6.0.3 (OK)]
  • 强制重新安装 jupyter:pip3 install --force-reinstall --upgrade jupyter
【解决方案3】:

问题是包tornado 6 和notebook 5.7.4 之间不兼容。 notebook was updated 于 2019 年 3 月 6 日,以解决此问题。目前,最好的解决方法如下:

使用点子

$ pip install -U jupyter

使用 pipenv

$ pipenv update jupyter

【讨论】:

    【解决方案4】:

    使用以下命令重置您的 jupyter notebook 配置文件以重置 jupyter_notebook_config.py 的默认配置

    jupyter notebook --generate-config
    

    【讨论】:

      【解决方案5】:

      不要降级龙卷风。相反,强制重新安装 jupyter。

      pip3 install --force-reinstall --upgrade jupyter
      

      参考:https://github.com/jupyter/notebook/issues/4439

      【讨论】:

      • 我想你的意思是pip3 install --force-reinstall --upgrade jupyter
      • 这对我不起作用:(
      【解决方案6】:

      安装 TensorFlow.js 时会出现此问题。

      当您安装 TensorFlow.js 时,它还会安装 prompt-toolkit-1.0.14,这会导致问题。

      安装 TensorFlow.js 后,您只需安装 prompt-toolkit-3.0.5 即可通过在命令提示符中运行以下代码来解决此问题:

      pip install prompt-toolkit==3.0.5
      

      【讨论】:

      • 这个问题与 TensorFlow.js 无关,显然它与 Jupyter 使用的 tornado 框架有关
      猜你喜欢
      • 2021-01-16
      • 1970-01-01
      • 1970-01-01
      • 2021-08-13
      • 2020-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多