Launch IPython notebook with selected browser
Question:
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).
Answers:
Why not use
--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
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
I uncomment this line and change into False, not to make ipython notebook open a web browser at start, so we can point the ipython notebook address in an active web browser.
# 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
Better still, I pin the address in my Firefox to make it active everytime I open the browser.
I tried what JPG and norfeldt suggested. It worked perfectly on my Windows 7 computer. Here is a copy of the modified section of ipython_notebook_config.py (located under C:Users’your username’.ipython to use Safari as the default browser for notebook. As norfeldt said, please notice the u before ‘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'
I set the environment variable BROWSER to the the executable of the browser (in my case Google Chrome), and Ipython Notebook started in the browser I liked.
PS H:> $env:BROWSER = "C:Program Files (x86)GoogleChromeApplicationchrome.exe"
PS H:> $env:BROWSER
C:Program Files (x86)GoogleChromeApplicationchrome.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).
Without coding, you can just set your default browser to Chrome or Firefox etc. It works for my windows system.
On my mac, I got the following command to use Firefox instead of my default Chrome:
jupyter notebook --browser firefox
This is not a real answer. I just want to share with the less computer savvy what JPG’s answer looks like step-by-step. Presumably, on Windows Explorer (screen capture attached below), the file jupyter_notebook_config.py
is listed:
In my case, the directory for the file (on top menu of Explorer) was C:UsersMy_name.jupyter
The second part of the answer can be implemented by simply pasting:
import webbrowser
webbrowser.register('firefox', None, webbrowser.GenericBrowser('C:\Program Files (x86)\Mozilla Firefox\firefox.exe'))
c.NotebookApp.browser = 'firefox'
in the space on the space seen on the screen capture below, corresponding to the jupyter_notebook_config.py
opened within PyCharm:
… only that I set it up to open in Opera:
import webbrowser
webbrowser.register('opera', None, webbrowser.GenericBrowser('C:\Program Files (x86)\Opera\launcher.exe'))
c.NotebookApp.browser = 'opera'
When you execute the below code in command prompt it gives the result link which you can copy in any browser to open Jupiter notebook.
jupyter notebook --browser firefox
to make it work with brave
and chrome
you need to append a %s
param that represents the URL. Tested the following on Linux terminal and works great:
jupyter notebook --browser="google-chrome %s"
jupyter notebook --browser="brave-browser %s"
firefox doesn’t need %s
jupyter notebook --browser=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
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).
Why not use
--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
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
I uncomment this line and change into False, not to make ipython notebook open a web browser at start, so we can point the ipython notebook address in an active web browser.
# 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
Better still, I pin the address in my Firefox to make it active everytime I open the browser.
I tried what JPG and norfeldt suggested. It worked perfectly on my Windows 7 computer. Here is a copy of the modified section of ipython_notebook_config.py (located under C:Users’your username’.ipython to use Safari as the default browser for notebook. As norfeldt said, please notice the u before ‘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'
I set the environment variable BROWSER to the the executable of the browser (in my case Google Chrome), and Ipython Notebook started in the browser I liked.
PS H:> $env:BROWSER = "C:Program Files (x86)GoogleChromeApplicationchrome.exe"
PS H:> $env:BROWSER
C:Program Files (x86)GoogleChromeApplicationchrome.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).
Without coding, you can just set your default browser to Chrome or Firefox etc. It works for my windows system.
On my mac, I got the following command to use Firefox instead of my default Chrome:
jupyter notebook --browser firefox
This is not a real answer. I just want to share with the less computer savvy what JPG’s answer looks like step-by-step. Presumably, on Windows Explorer (screen capture attached below), the file jupyter_notebook_config.py
is listed:
In my case, the directory for the file (on top menu of Explorer) was C:UsersMy_name.jupyter
The second part of the answer can be implemented by simply pasting:
import webbrowser
webbrowser.register('firefox', None, webbrowser.GenericBrowser('C:\Program Files (x86)\Mozilla Firefox\firefox.exe'))
c.NotebookApp.browser = 'firefox'
in the space on the space seen on the screen capture below, corresponding to the jupyter_notebook_config.py
opened within PyCharm:
… only that I set it up to open in Opera:
import webbrowser
webbrowser.register('opera', None, webbrowser.GenericBrowser('C:\Program Files (x86)\Opera\launcher.exe'))
c.NotebookApp.browser = 'opera'
When you execute the below code in command prompt it gives the result link which you can copy in any browser to open Jupiter notebook.
jupyter notebook --browser firefox
to make it work with brave
and chrome
you need to append a %s
param that represents the URL. Tested the following on Linux terminal and works great:
jupyter notebook --browser="google-chrome %s"
jupyter notebook --browser="brave-browser %s"
firefox doesn’t need %s
jupyter notebook --browser=firefox