使用选定的浏览器启动IPython笔记本 [英] Launch IPython notebook with selected browser
问题描述
我正在尝试使用非默认浏览器启动IPython(在我的情况下是Firefox)
并认为我可以复制复制脚本给出在此博客中
I am trying to start IPython with a non default browser (in my case Firefox) and thought I could replicate the replicate the script given in this blog
我在Windows 7上
我将以下代码放在一个文件中说module.py
I put the following code in a file say "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/'])
但是当我从命令行运行它时
However when I run it from the command line
python C:\Users\mugabal\Desktop\module1.py
它执行第一行但不执行第二行(两行都单独工作)
It execute the first line but not the second one (both lines work fine individually)
我的问题(用更通用的术语)我如何启动流程并告诉它不高举控制台窗口?
My question (in a more general term) how can I launch a process and tell it not to highjack the console window?
如果我已经监督了一个明显的解释,我提前道歉但我在子流程文档和这个平台上都看了
I apologize in advance if I have overseen an obvious explanation but I looked both in the subprocess documentation and on this platform
-----更新-----
我应该补充说我尝试使用选定的浏览器启动IPython但是无法弄清楚如何让它工作
I should have added that I tried to launch IPython with selected browser but could not figure out how to get it work
>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命令提示符窗口中的以下命令按预期工作:
To be precise, the following command in a Windows command prompt window works as expected:
start firefox
但是
ipython notebook --browser=firefox
不起作用(与上面相同的错误)。
does not work (same error as above).
推荐答案
我在Windows上遇到了同样的问题并以这种方式工作:
I had the same problem on windows and got it work this way:
-
使用命令
创建配置文件ipython配置文件创建默认值
编辑ipython_notebook_config.py文件,搜索行
Edit ipython_notebook_config.py file, search for line
#c.NotebookApp。 browser =''
并将其替换为
import webbrowser
webbrowser.register('firefox', None, webbrowser.GenericBrowser('C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe'))
c.NotebookApp.browser = 'firefox'
然后它对我有用。
希望它会对你有帮助。
JPG
这篇关于使用选定的浏览器启动IPython笔记本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!