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

use*_*144 45 python windows subprocess ipython

我试图用非默认浏览器启动IPython(在我的情况下是Firefox),并且我认为我可以复制复制该博客中给出的脚本

我在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/'])
Run Code Online (Sandbox Code Playgroud)

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

 python C:\Users\mugabal\Desktop\module1.py
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

我应该补充一点,我试图用选定的浏览器启动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.**
Run Code Online (Sandbox Code Playgroud)

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

start firefox 
Run Code Online (Sandbox Code Playgroud)

ipython notebook --browser=firefox 
Run Code Online (Sandbox Code Playgroud)

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

JPG*_*JPG 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'
Run Code Online (Sandbox Code Playgroud)

那对我有用.

希望它会对你有所帮助.

JPG

  • 对于 Jupyter notebook,使用命令 `jupyter notebook --generate-config` 创建配置并编辑 jupyter_notebook_config.py 文件,如上所述 (2认同)

JBW*_*ore 25

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

jupyter notebook --browser firefox
Run Code Online (Sandbox Code Playgroud)


Mat*_*att 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
Run Code Online (Sandbox Code Playgroud)


Ton*_*oni 9

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

在此输入图像描述

在我的例子中,该文件的目录(在资源管理器的顶层菜单上)是 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'
Run Code Online (Sandbox Code Playgroud)

在屏幕下方的空间上捕获下方,对应jupyter_notebook_config.py于PyCharm内打开:

在此输入图像描述

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

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


小智 5

我取消注释此行,并将其更改为False,而不是让ipython Notebook在启动时打开Web浏览器,因此我们可以将ipython Notebook的地址指向活动的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
Run Code Online (Sandbox Code Playgroud)

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