17

I would like to keep firefox as my system default browser on my Mac, but launch IPython Notebook in Chrome[1].

This answer led me to my ipython_notebook_config.py file but I can't get an instance of Chrome running. After c = get_config() and import webbrowser, I've tried:

  1. webbrowser.register(u'chrome', None, webbrowser.Chrome())

  2. webbrowser.register(u'chrome', webbrowser.Chrome)

  3. webbrowser.register(u'chrome', None, webbrowser.GenericBrowser('/Applications/Browsers/Chrome.app'))

  4. webbrowser.register(u'chrome', None, webbrowser.GenericBrowser('/Applications/Browsers/Chrome.app/Contents/MacOS/Google\ Chrome'))

All followed by c.NotebookApp.browser = u'chrome'

I've fiddled with webbbrowser in the interpreter, and couldn't figure out how to create an instance of Chrome.


[1]: PS Why is IPython Notebook so slow in firefox, especially for pylab with the inline backend? It's orders of magnitude faster (for rendering, scrolling, etc) in chrome.

Community
  • 1
  • 1
askewchan
  • 45,161
  • 17
  • 118
  • 134
  • I am having very similar issues. Chrome won't open, whatever I try in the `python_notebook_config.py` (registering a new browser, different ways to specify the path to `/Applications/Browsers/Chrome.app` or its "Contents" with or without spaces escaped, etc. There is [another stackoverflow discussion](http://stackoverflow.com/questions/15632663/launch-ipython-notebook-with-selected-browser) and there is an [open issue](https://github.com/ipython/ipython/issues/3028) I would love this to be resolved. Also, I also wonder, why it IPython seems much more stable and faster on Chrome. – Claus Aug 29 '13 at 11:43
  • I use the notebook in Firefox and it runs at a perfectly usable speed. Is your Firefox up to date? Do you have any addons that might be interfering? Can you replicate this with a clean Firefox profile, or on another machine? – Thomas K Aug 29 '13 at 16:49
  • @ThomasK Perhaps ... I use Firefox 'Aurora' so it's up to date, but if my addons or plugins are slowing it down then my preference is to use Chrome so that firefox can be the way I want it to be for web browsing. – askewchan Aug 30 '13 at 01:57
  • @askewchan: That's fine, I was more trying to figure out whether there's a problem that we (IPython) can fix. – Thomas K Aug 30 '13 at 02:32

9 Answers9

15

Since the great switch to Jupyter, and with recent versions of OS X (e.g., Yosemite), Jupyter/iPython (e.g., 4.0.1), and Chrome (e.g., 47), things have changed a bit. Jupyter/iPython no longer puts the notebook config file in ~/.ipython; it's now in ~/.jupyter, and the default file is generated with

jupyter notebook --generate-config

If you have an existing ipython_notebook_config.py you can migrate it with jupyter migrate (H/T).

After generating or migrating your config file, add the following line to jupyter_notebook_config.py:

c.NotebookApp.browser = u'/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome %s'
Community
  • 1
  • 1
Dan
  • 1,105
  • 12
  • 15
12

Based on this answer, (running Python 2.7.3 and IPython-0.13.1 on Linux), all I had to set in my ipython_notebook_config.py was

c.NotebookApp.browser = u'/usr/bin/google-chrome %s'

I'm guessing, setting c.NotebookApp.browser to /Applications/Browsers/Chrome.app/Contents/MacOS/Google Chrome %s should work for you.

Community
  • 1
  • 1
punchagan
  • 5,566
  • 1
  • 19
  • 23
  • Thanks for the suggestion but this doesn't seem to work. It must have access to launch chrome, because I get an error that chrome unexpectedly quit. I might be using the wrong binary, but I'm not sure where else to point. The `' %s'` helps though, I think. – askewchan Jun 18 '13 at 16:57
  • Does `/Applications/Browsers/Chrome.app/Contents/MacOS/Google Chrome http://google.com` work on the terminal? Can you try by adding a `\` to escape the space? – punchagan Jun 18 '13 at 17:35
  • Must be the issue. `~$ /Applications/Browsers/Chrome.app/Contents/MacOS/Google\ Chrome http://www.google.com` `[57636:2307:0618/191916:ERROR:process_singleton_mac.cc(106)] Unable to obtain profile lock.` – askewchan Jun 18 '13 at 23:20
  • 1
    If you don't have a `ipython_notebook_config.py`, you should run `ipython profile create default` and it will appear in `~/.ipython/profile_default` or `~/.config/ipython/profile_default` or similar. – Ian Hincks Jun 02 '14 at 15:26
8

On OS X, you can put the following in ipython_notebook_config.py to open Chrome:

c.NotebookApp.browser = u'/usr/bin/open -a Google\\ Chrome %s'

The executable in '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' fails for me with 'unable to obtain profile lock', so going through 'open' is the only simple alternative I see.

MHH
  • 363
  • 3
  • 6
5

This might not be the right things to do , but

$ open -a Google\ Chrome http://localhost:8888
$ open -a Firefox http://localhost:8888

Works from me (only on mac) to open any url in one of the 2 browser.

Use the --no-browser option and make an bash function that does that. Or even have a bookmark in Chrome.

Matt
  • 27,170
  • 6
  • 80
  • 74
  • see: http://ipython.org/ipython-doc/stable/interactive/public_server.html#running-a-public-notebook-server to understand how you can configure your session when you launch it this way (where here, your 'remote notebook server' is of course just localhost) – Matt S. Nov 01 '13 at 21:30
4

For people who want to make firefox their default for ipython notebooks (where it is not necessarily the system default), adding the following line to ipython_notebook_config.py should be sufficient:

c.NotebookApp.browser = 'Firefox'

For me, this was better than linking to the application file directly because it avoids the error: A copy of Firefox is already open. Only one copy of Firefox can be open at a time.

Alex
  • 12,078
  • 6
  • 64
  • 74
3

This worked for me on OSX Mavericks:

c.NotebookApp.browser = u'/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome %s'
Alex C-W
  • 43
  • 5
3

For future reference, this works looks the most elegant way to edit jupyter_notebook_config.py for me on macOS:

c.NotebookApp.browser = u'open -a "Google Chrome" %s'

You can obviously replace "Google Chrome" with any other browser.

Full procedure:

  1. jupyter notebook --generate-config
  2. open ./jupyter/jupyter_notebook_config.py
  3. Find the line #c.NotebookApp.browser and edit it as above
Pincopallino
  • 651
  • 1
  • 8
  • 21
1

If you don't want to open the browser at all, you can add ipython notebook --no-browser.

RussellStewart
  • 5,293
  • 3
  • 26
  • 23
  • Handy if using ipython on VM, but you want to use host browser. For example: __ipython notebook --ip=0.0.0.0 --port=3000 --no-browser mynotebook.ipynb__ (VM: nat, with port-forwarding on port 3000) – 681234 Nov 24 '15 at 12:47
0

For Mac users, the best way is to change the default browser from the system preferences/General, and enjoy your new browser for jupyter notebook.