【问题标题】:How to set jupyter notebook to open on browser automatically如何设置 jupyter notebook 自动在浏览器上打开
【发布时间】:2019-09-09 09:19:38
【问题描述】:

所以我在尝试打开 jupyter 笔记本时没有问题,但由于某种原因,无论我尝试做什么,我都无法让它在浏览器中自动打开。我按照这些帖子无济于事: unable to open jupyter(ipython) notebook on browser https://github.com/jupyter/notebook/issues/2130

我通过jupyter notebook --generate-config 创建了jupyter 配置并修改了这些设置:

c.NotebookApp.browser = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' c.NotebookApp.open_browser = True
c.NotebookApp.webbrowser_open_new = 2

它仍然没有在 Chrome 中自动打开笔记本。我想知道我是否在做一些愚蠢的事情,但我不知道还能做什么。我在 Windows 10 上运行并通过 cygwin 启动 jupyter。当我在 cygwin 中输入jupyter notebook(修改设置文件后)时,它给了我这个输出:

$ jupyter notebook
[I 21:57:41.782 NotebookApp] Serving notebooks from local directory: /cygdrive/c/home
[I 21:57:41.782 NotebookApp] The Jupyter Notebook is running at:
[I 21:57:41.782 NotebookApp] http://localhost:8888/?token=373da6a3a3ed7c5fb991f0b3b1042bff22e3fa946aea8bc1
[I 21:57:41.782 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 21:57:41.799 NotebookApp]

To access the notebook, open this file in a browser:
    file:///cygdrive/c/home/.local/share/jupyter/runtime/nbserver-1003-open.html
Or copy and paste one of these URLs:
    http://localhost:8888/?token=373da6a3a3ed7c5fb991f0b3b1042bff22e3fa946aea8bc1

我还能做些什么让它在浏览器中自动打开吗?

更新:我找到了这个链接,但它也不起作用:Launch IPython notebook with selected browser

我也发现这个设置不对:c.NotebookApp.browser = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe',应该是:c.NotebookApp.browser = 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'。但我仍然没有任何进展。 :(

【问题讨论】:

  • 我在 Windows 10 的 WSL 上也有类似的行为。Jupyter 没有打开笔记本启动,而是打开另一个页面 file:///home/user/.local/share/jupyter/runtime/nbserver -232-open.html .
  • 临时破解可能会半自动启动浏览器:):nohup jupyter lab & sleep 5; /mnt/c/Program\ Files\ \(x86\)/SeaMonkey/seamonkey.exe grep -om1 http.* nohup.out` `
  • 嘿,感谢您的评论!我无法弄清楚我的问题,只是从头开始重新安装所有东西。我所说的一切,是指 Cygwin、python、我所有的库、依赖项以及我以前拥有的任何实用程序。我不知道以前的问题是什么,但是对我的 cygwin 和 python 安装进行简单的刷新解决了我所有的问题。如果您对此问题有任何其他建议,我们将不胜感激!
  • 我找不到任何其他解决方案。最近一个相关问题here,问题可能与与windows的集成有关。

标签: python jupyter-notebook jupyter


【解决方案1】:

将此行添加到您的jupyter_notebook_config.py 文件中:

c.NotebookApp.use_redirect_file = False

这应该会在您的浏览器中使用localhost/127.0.0.1 URL 自动打开 jupyter 笔记本。

为了完整起见,请提供更多信息:

  • 配置文件应在~/.jupyter/jupyter_notebook_config.py 中找到。如果缺少可以使用以下命令生成(如您所做的那样):jupyter notebook --generate-config
  • 这是讨论更改的Github issue(同样的解决方案也突出显示here
  • 这是documentation 中的参考资料

【讨论】:

    【解决方案2】:

    您可以通过在配置文件中将此设置设置为“false”来修复它

    如果尚未完成,请生成配置文件:jupyter notebook --generate-config

    然后在 ~/.jupyter/jupyter_notebook_config.py 中将 NotebookApp.use_redirect_file 更新为 False(默认为 True)

    (来自https://jupyter-notebook.readthedocs.io/en/stable/config.html

    NotebookApp.use_redirect_fileBool

    默认:真

    通过重定向文件禁用启动浏览器 对于 notebook > 5.7.2 的版本,添加了一项安全功能措施,以防止用于启动浏览器的身份验证令牌可见。此功能使多用户系统上的其他用户难以像您一样在 Jupyter 会话中运行代码。

    但是,在某些环境(如适用于 Linux 的 Windows 子系统 (WSL) 和 Chromebook)中,使用重定向文件启动浏览器可能会导致浏览器无法加载。这是因为运行时和浏览器之间的文件结构/路径不同。 将此设置禁用为 False 将禁用此行为,允许浏览器使用 URL 和可见令牌启动(如前所述)。

    【讨论】:

      【解决方案3】:

      在命令行输入:

      jupyter notebook --browser=<Browser>

      <Browser>ChromeSafariFirefox

      【讨论】: