繁体   English   中英

如何设置jupyter notebook在浏览器中自动打开

[英]How to set jupyter notebook to open on browser automatically

因此,我在尝试打开 jupyter notebook 时没有遇到任何问题,但出于某种原因,无论我尝试做什么,我都无法在浏览器中自动打开它。 我关注这些帖子无济于事: 无法在浏览器上打开 jupyter(ipython) 笔记本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' 但是我仍然没有取得任何进展。 :(

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

c.NotebookApp.use_redirect_file = False

这应该会在浏览器中使用localhost / 127.0.0.1 URL 自动打开 jupyter notebooks。

为了完整起见的更多信息:

  • 配置文件应该在~/.jupyter/jupyter_notebook_config.py中找到。 如果缺少可以使用以下命令生成(就像你所做的那样): jupyter notebook --generate-config
  • 这是讨论更改的Github 问题此处也突出显示了相同的解决方案)
  • 这是文档中的参考

在命令行中,键入:

jupyter notebook --browser=<Browser>

<Browser>ChromeSafariFirefox等。

您可以通过在配置文件中将此设置设置为“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 和可见令牌(与以前一样)启动。

暂无
暂无

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

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