Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
197 views
in Technique[技术] by (71.8m points)

python - Launch IPython notebook with selected browser

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

I am on Windows 7

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 FirefoxFirefox.exe', '-new-tab', 'http://127.0.0.1:8888/'])

However when I run it from the command line

 python C:UsersmugabalDesktopmodule1.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

----- UPDATE -----

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 FirefoxFirefox.exe'
... 
[NotebookApp] The IPython Notebook is running at: http://127.0.0.1:8888/
...
**[NotebookApp] No web browser found: could not locate runnable browser.**

To be precise, the following command in a Windows command prompt window works as expected:

start firefox 

but

ipython notebook --browser=firefox 

does not work (same error as above).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had the same problem on windows and got it work this way:

  • Create a config file with command ipython profile create default

  • Edit ipython_notebook_config.py file, search for line

#c.NotebookApp.browser =''

and replace it with

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

then it works for me.

Hope it will help you.

JPG


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...