python - 如何将 jupyter notebook 设置为在浏览器上自动打开

标签 python jupyter-notebook jupyter

所以我在尝试打开 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。当我输入 jupyter notebook (修改设置文件后)在 cygwin 中,它给了我这个输出:

$ 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 自动打开 jupyter notebooks/127.0.0.1网址。
为完整起见,更多信息:
  • 配置文件应该在 ~/.jupyter/jupyter_notebook_config.py 中找到.如果可以使用以下命令生成缺失(如您所做的那样):jupyter notebook --generate-config
  • 这是Github issue讨论更改的地方(同样的解决方案也被突出显示 here )
  • 这是 documentation 中的引用
  • 关于python - 如何将 jupyter notebook 设置为在浏览器上自动打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55756151/

    相关文章:

    python - 在python中强制重命名文件

    python - 获取 pandas DataFrame 中的非空元素

    python - 如何在Tornado中使用静态文件

    python-3.x - 在电池jupyter笔记本中关闭警告

    python - 从 jupyter 笔记本运行 python 程序,同时传递文件名作为参数

    python - vscode ipython 交互式内核启动和执行缓慢

    jupyter - 从笔记本中保存 Jupyter 笔记本的 html

    python - 一个阵列轴的快速插补

    java - Jupyter Notebook 的 Gradle 依赖项

    amazon-ec2 - 使用 dask labextensiontion 连接到远程集群