使用选定的浏览器启动IPython笔记本

问题描述 投票:44回答:9

我试图用非默认浏览器启动IPython(在我的情况下是Firefox)并且认为我可以复制复制脚本给定in this blog

我在Windows 7上

我把以下代码放在一个文件中说“module.py”

import subprocess
subprocess.call("ipython notebook --no-browser", shell=True)
subprocess.call([r'C:\Program Files (x86)\Mozilla Firefox\Firefox.exe', '-new-tab', 'http://127.0.0.1:8888/'])

但是,当我从命令行运行它时

 python C:\Users\mugabal\Desktop\module1.py

它执行第一行而不是第二行(两行都单独工作)

我的问题(用更通用的术语)我如何启动一个进程并告诉它不要高举控制台窗口?

如果我已经监督了一个明显的解释,我提前道歉,但我在子流程文档和这个平台上都看了

-----更新-----

我应该补充一点,我试图用选定的浏览器启动IPython,但无法弄清楚如何让它工作

>ipython notebook --browser='C:\Program Files (x86)\Mozilla Firefox\Firefox.exe'
... 
[NotebookApp] The IPython Notebook is running at: http://127.0.0.1:8888/
...
**[NotebookApp] No web browser found: could not locate runnable browser.**

确切地说,Windows命令提示符窗口中的以下命令按预期工作:

start firefox 

ipython notebook --browser=firefox 

不起作用(与上面相同的错误)。

python windows subprocess ipython
9个回答
66
投票

我在Windows上遇到了同样的问题,并以这种方式工作:

  • 使用命令ipython profile create default创建配置文件
  • 编辑ipython_notebook_config.py文件,搜索行

#c.NotebookApp.browser =''

并替换它

import webbrowser
webbrowser.register('firefox', None, webbrowser.GenericBrowser('C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe'))
c.NotebookApp.browser = 'firefox'

那对我有用。

希望它会对你有所帮助。

JPG


23
投票

在我的Mac上,我得到以下命令来使用Firefox而不是我的默认Chrome:

jupyter notebook --browser firefox

9
投票

为什么不用

--browser=<Unicode> (NotebookApp.browser)
    Specify what command to use to invoke a web browser when opening the
    notebook. If not specified, the default browser will be determined by the
   `webbrowser` standard library module, which allows setting of the BROWSER

9
投票

这不是一个真正的答案。我只是想与精通计算机的人分享一下,JPG的答案看起来是一步一步的。据推测,在Windows资源管理器(下面附带的屏幕截图)中,列出了文件jupyter_notebook_config.py

enter image description here

在我的例子中,该文件的目录(在资源管理器的顶层菜单上)是C:\Users\My_name\.jupyter

答案的第二部分可以通过简单粘贴来实现:

import webbrowser
webbrowser.register('firefox', None, webbrowser.GenericBrowser('C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe'))
c.NotebookApp.browser = 'firefox'

在下面的屏幕截图上看到的空间上的空间中,对应于PyCharm中打开的jupyter_notebook_config.py

enter image description here

...只是我把它设置为在Opera中打开:

import webbrowser
webbrowser.register('opera', None, webbrowser.GenericBrowser('C:\\Program Files (x86)\\Opera\\launcher.exe'))
c.NotebookApp.browser = 'opera'

5
投票

我取消注释这一行并更改为False,而不是让ipython笔记本在开始时打开Web浏览器,因此我们可以将ipython笔记本地址指向活动的Web浏览器。

# Whether to open in a browser after starting. The specific browser used is
# platform dependent and determined by the python standard library `webbrowser`
# module, unless it is overridden using the --browser (NotebookApp.browser)
# configuration option.
c.NotebookApp.open_browser = False

更好的是,我在我的Firefox中固定地址,使其在每次打开浏览器时都处于活动状态。


1
投票

我将环境变量BROWSER设置为浏览器的可执行文件(在我的案例中是Google Chrome),Ipython Notebook在我喜欢的浏览器中启动。

PS H:\> $env:BROWSER = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
PS H:\> $env:BROWSER
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
PS H:\>
PS H:\> ipython notebook
2015-02-19 14:05:01.690 [NotebookApp] Using existing profile dir: C:\\Users\\abc\\.ipython\\profile_default'
2015-02-19 14:05:01.832 [NotebookApp] Using MathJax from CDN: http://cdn.mathjax.org/mathjax/latest/MathJax.js
2015-02-19 14:05:01.901 [NotebookApp] The port 8888 is already in use, trying another random port.
2015-02-19 14:05:01.908 [NotebookApp] Serving notebooks from local directory: H:\
2015-02-19 14:05:01.908 [NotebookApp] 0 active kernels
2015-02-19 14:05:01.910 [NotebookApp] The IPython Notebook is running at: http://localhost:8889/
2015-02-19 14:05:01.910 [NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

1
投票

当您在命令提示符下执行以下代码时,它会提供结果链接,您可以在任何浏览器中复制该链接以打开Jupiter笔记本。

jupyter notebook --browser firefox

0
投票

我尝试过JPG和norfeldt的建议。它在我的Windows 7计算机上运行得很好。这是ipython_notebook_config.py的修改部分的副本(位于C:\ Users \'你的用户名'\。ipython下,使用Safari作为笔记本的默认浏览器。正如norfeldt所说,请注意你之前'C:\ ...)

# c.NotebookApp.certfile = u''

import webbrowser
webbrowser.register('safari', None, webbrowser.GenericBrowser(u'C:\\Program Files (x86)\\Safari\\safari.exe'))
c.NotebookApp.browser = 'safari'

-2
投票

如果没有编码,您可以将默认浏览器设置为Chrome或Firefox等。它适用于我的Windows系统。

© www.soinside.com 2019 - 2024. All rights reserved.