72

I'm on Linux Mint 17.3.

How do I change the default browser used by the Jupyter notebook?

I have installed the notebook as a part of Anaconda 3 and it opens up in my default browser—Chrome. But for some reason, Chrome won't let me make a new ipynb. Clicking the 'new' button simply doesn't do anything. So I copied the notebook url to Firefox and it works perfectly fine there.

Is there a way I can make it work with Chrome? Otherwise, how do I change the default browser? The usual answer I've come across is that I have to change the c.NotebookApp.browser option, but I can't find a way to do so, since trying to find ipython_notebook_config in the terminal comes up with 4 results:

./anaconda3/lib/python3.5/site-packages/jupyter_core/tests/dotipython/profile_default/ipython_notebook_config.py
./anaconda3/lib/python3.5/site-packages/jupyter_core/tests/dotipython_empty/profile_default/ipython_notebook_config.py
./anaconda3/pkgs/jupyter_core-4.0.6-py35_0/lib/python3.5/site-packages/jupyter_core/tests/dotipython/profile_default/ipython_notebook_config.py
./anaconda3/pkgs/jupyter_core-4.0.6-py35_0/lib/python3.5/site-packages/jupyter_core/tests/dotipython_empty/profile_default/ipython_notebook_config.py
prosoitos
  • 6,679
  • 5
  • 27
  • 41
Kevin
  • 841
  • 1
  • 7
  • 7

6 Answers6

133

You can create jupyter_notebook_config.py by:

jupyter notebook --generate-config

Then you go to

~/.jupyter/jupyter_notebook_config.py

and change

# c.NotebookApp.browser = ''

to for example:

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

You can choose which ever browser is installed. You'll find the path for example by typing which firefox Do not forget to delete the #

Richard
  • 56,349
  • 34
  • 180
  • 251
Christof
  • 1,446
  • 1
  • 10
  • 3
  • Many thanks for explaining the process of making the config file! But sadly, this doesn't work. After I set the browser to firefox(the correct path, I checked), the server starts but it just fails to open any browser window, let alone firefox. Reverts back to normal(Chrome) when I comment it out. Any suggestions about why it might have a problem opening up firefox? Thanks. – Kevin Feb 23 '16 at 19:50
  • 1
    @Kevin have you tried simply running 'firefox' from the command line? If that works, I would expect the same (without the /usr/bin prefix) to work for Jupyter. – TimStaley Apr 08 '16 at 15:14
  • 10
    Although not stated explicitly, jupyter uses the [`webbrowser`](https://docs.python.org/2/library/webbrowser.html) module to run this, so the [suggestion here](http://stackoverflow.com/a/24353812) works. I.e. on Mac OS X, the "command" should be `c.NotebookApp.browser = u'open -a /Applications/Google\ Chrome.app %s'`. – mforbes Nov 01 '16 at 05:38
  • 1
    This sort of worked for me, but every time I open jupyter notebook, it takes me to the url: http://openurl%28http//localhost:8888/tree,new-page) . Any idea how to fix that? – wordsforthewise Jan 31 '17 at 06:28
  • 2
    Thanks! This worked for me on Windows by providing a Unix-style path (see http://stackoverflow.com/questions/24873302/python-generic-webbrowser-get-open-for-chrome-exe-does-not-work). I use Firefox by default for security reasons but I want that security off for jupyter, so this is a great solution. Also I totally forgot to uncomment the line! :) – Matt Davis Feb 26 '17 at 18:56
  • 3
    To sum it up, under Windows the following string inside your `config_file.py` works: `c.NotebookApp.browser = 'C:/Program Files (x86)/Mozilla Firefox/firefox.exe %s'`. Do not forget the `%s` at the end. – Pavlo Dyban Aug 25 '17 at 07:25
  • `c.NotebookApp.browser = '/usr/bin/google-chrome-stable %s'` should be the line on linux – Dusan Maksic May 24 '20 at 07:02
12

The accepted answer is great, here is a solution if you want to change it one time:

jupyter-notebook --browser=firefox

Of course you could make a bash wrapper script with this command or create a .desktop file that would let you launch it in your preferred browser every time you use that launcher.

An example wrapper script could look like this:

#!/bin/bash
jupyter-notebook --browser=firefox

You could then place it in your PATH, e.g. $HOME/bin/jnbff.sh, so you can easily launch it from any directory by simply typing its name.

Sidenote: the dash in jupyter-notebook allows for tab-completion, the usually recommended way with space (i.e. jupyter notebook) doesn't.

jena
  • 281
  • 4
  • 10
2

The following worked for me on win10. For firefox: c.NotebookApp.browser = u'c:/Program Files/Mozilla Firefox/firefox.exe %s'

For chrome c.NotebookApp.browser = u'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'

note the 1) "" vs "/" 2) the u and %s

py_newbie
  • 329
  • 2
  • 9
2

Update for notebooks running in the JupyterLab interface

As JupyterLab is increasingly replacing Jupyter Notebook, here is an update to customize the default browser in which JupyterLab is launched. The solution is extremely similar to the accepted answer from @Christof:

jupyter-lab --generate-config

will create ~/.jupyter/jupyter_lab_config.py in which the line:

# c.ServerApp.browser = ''

can be uncommented and edited with the default browser of choice. For instance:

c.ServerApp.browser = '/usr/bin/qutebrowser %s'
prosoitos
  • 6,679
  • 5
  • 27
  • 41
0

I tried the accepted answer in Ubuntu 22.04 answer, but it didn't work for me which I discovered was because Firefox is packaged as a snap package in Ubuntu 22.04. I circumvented this obstacle by installing Web (Web browser for GNOME) with this command:

sudo apt install epiphany 

The results of which epiphany are /usr/bin/epiphany which you will need to know when you get to the second to last paragraph of the accepted answer. It still won't work though, so you have to do one more step. Change the ownership of the ~/.local/share/jupyter directory from root to user. Instead of user in the below command replace it with your own username that you login with.

sudo chown -R user:user ~/.local/share/jupyter 
karel
  • 5,489
  • 46
  • 45
  • 50
-5

Chrome Browser > Settings (Scroll all the way to the bottom) > Change Default browser to Chrome > New window would pop up. Change the default browser there!

Worked for me! (Windows 10 User)

Surbhi
  • 95
  • 1
  • 1