Force Jupyter Notebook *not* to open a web browser
Asked Answered
C

4

30

I'm running Jupyter notebooks (Python 3) on a remote cluster that I'm connected/tunneled to over SSH.

Jupyter's default behavior is to try to open the dashboard in a web browser when it launches -- aparently (I only just updated), at some point they switched to the Python 3 webbrowser library for this.

According to webbrowser's documentation:

text-mode browsers will be used if graphical browsers are not available or an X11 display isn’t available.

This is exactly what happens. I run jupyter notebook, webbrowser launches elinks, and my one-time authentication token gets eaten, preventing me from connecting to the notebook.

Jupyter isn't configured to use a browser -- c.NotebookApp.browser is commented out in my config -- and running BROWSER="" jupyter notebook doesn't help either.

How can I force Jupyter not to open any browser?

Clinical answered 6/9, 2018 at 19:6 Comment(0)
P
19
jupyter notebook --generate-config

Then edit ~/.jupyter/jupyter_notebook_config.py and Add

NotebookApp.open_browser = False
Phila answered 6/9, 2018 at 19:16 Comment(0)
F
37

jupyter-notebook --help includes the following:

--no-browser
    Don't open the notebook in a browser after startup.
Fantasm answered 6/9, 2018 at 19:9 Comment(2)
Thank you. I was in the help page, don't know how I missed this.Clinical
thankyou ... i am searching for this featureReeding
P
19
jupyter notebook --generate-config

Then edit ~/.jupyter/jupyter_notebook_config.py and Add

NotebookApp.open_browser = False
Phila answered 6/9, 2018 at 19:16 Comment(0)
C
8

You can achieve this by specifying --no-browser:

$ jupyter notebook --no-browser

I also recommend that you specify the port you want to use:

jupyter notebook --no-browser --port= <port_number>

ie:

$ jupyter notebook --no-browser --port=8888

You have to keep in mind that when you do this, jupyter will provide you with a token on the console, token that the server will ask you when connect remotely through the browser.

If you want to simplify this procedure, you can set a password that is easier for you to remember. To do this, you can run in a console:

$ jupyter notebook --generate-config

and later:

$ jupyter notebook password

This last command will ask you for the password that you wish to use to enter remotely.

Regards!

Communitarian answered 6/9, 2018 at 19:24 Comment(0)
D
1

If you use jupyter lab or other jupyter tooling, the browser might still open.

To always disable the browser for all jupyter commands, edit your default config at:

~/.jupyter/jupyter_notebook_config.py

And add the following lines:

c.NotebookApp.open_browser = False
c.LabApp.open_browser = False
c.ServerApp.open_browser = False
c.ExtensionApp.open_browser = False

Source:

From Jupyter help pages:

--no-browser
    Prevent the opening of the default url in the browser.
    Equivalent to: [--ServerApp.open_browser=False --ExtensionApp.open_browser=False]
Deposition answered 21/3 at 18:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.