Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launching notebook to browser on WSL #4594

Closed
thomasaarholt opened this issue Apr 26, 2019 · 42 comments
Closed

Launching notebook to browser on WSL #4594

thomasaarholt opened this issue Apr 26, 2019 · 42 comments

Comments

@thomasaarholt
Copy link
Contributor

WSL = Windows Subsystem for Linux aka "Bash on Ubuntu on Windows" or "Running Linux on Windows".

Currently, in order for WSL to recognise Windows browsers, the $BROWSER environment variable needs to be set:
export BROWSER='/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'

However, the following text printed after calling jupyter notebook helps explain my issue.

    To access the notebook, open this file in a browser:
        file:///home/thomasaar/.local/share/jupyter/runtime/nbserver-5243-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=0276d3335ad5a259bd29effdbd1716f4591c85a10674501f

Currently, the browser window opens with the first of those two links. And since Chrome is a windows browser, that address doesn't exist for it.

My questions are:

  1. Is there a better way of doing this?
  2. If not, is there a way to feed chrome the second address (which does work if I manually paste it).
@raghavven
Copy link

I tried fixing it by typing the following command and then run 'jupyter notebook'
export BROWSER='/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'
The chrome still says 'unable to connect to host'

Kindly help.

@quinterojosuej
Copy link

A solution is to download firefox or chrome in your WSL
By downloading the browser you will need to use Xlaunch or another visual hoster.

This should work, make sure to test that you have the browser working after installing before testing with jupyter notebook.

@llinfeng
Copy link

llinfeng commented Jul 30, 2019

Here go more details to launch from a native browser on WSL:

  • Browser: I used Firefox as Chrome turned out to be a hassle to install on WSL
sudo apt install firefox
  • Jupyter config: update the setting in ~/.jupyter/jupyter_notebook_config.py once firefox is callable from WSL
c.LabApp.browser = '/usr/bin/firefox --new-window %s'
  • Get a proper X-server for Windows (I use X410) and set up the following in your default shell (usually bash, unless you change it to zsh or something else).
export DISPLAY=localhost:0.0

Caveats: per my testing, new windows got opened up automatically after putting in the settings listed above. Yet, the Firefox window is "oversized," and I needed to look for it and resize it properly. Please advise if you have a better way to rescale the auto-started Firefox by jupyter lab command.


A bit more echoing for the original posting:

Before switching to firefox on WSL, jupyter notebook did not launch at all when I got the browser configured to be the local Chrome on Windows. Instead, jupyter lab got me the reported troublesome behavior, since May 2019 or so. I clearly recall that such starting trouble did not exist back in 2018.

@raghavven
Copy link

I installed firefox using the command 'sudo apt install firefox'.
I tried to open firefox from the terminal using the following commands. 'firefex' and /usr/bin/firefox. But it gave me the following error.

Failed to connect to Mir: Failed to connect to server socket: No such file or directory
Unable to init server: Broadway display type not supported: localhost:8888
Error: cannot open display: localhost:8888

I am not sure how to proceed. My windows firewall is also turned off. Kindly help.

Thanks.

@llinfeng
Copy link

@raghavven Let's try to start simple: how about simply start firefox from terminal? Does it give you an error?

  • If so, you will need to configure two things: 1. put export DISPLAY=localhost:0.0 into your ~/.bashrc (or whatever dotfile for your shell); and 2. run a local X-server on Windows. Xming is free and should work out of the box.

Then, it seems that your WSL did not install Firefox to /user/bin/firefox. No worries. You will then want to look up where it is by issuing which firefox in your command line. Then, you want to update the ~/.jupyter/jupyter_notebook_config.py accordingly.

@raghavven
Copy link

Dear IIinfeng

I installed firefox and is found in the path (after typing the command"type -a firefox"), '/usr/bin/firefox'.

When I try to start firefox by simply typing 'firefox' in the terminal, I get the following error.

Error: no DISPLAY environment variable specified.

Kindly help.

Thanks.

@llinfeng
Copy link

llinfeng commented Jul 30, 2019

How about you try to run the following command in your WSL terminal: export DISPLAY=localhost:0.0?

Then, within the same terminal session, try to run firefox directly? If it did not work, please write back with what you see from echo $DISPLAY command.

@llinfeng
Copy link

Please note, the performance of these firefox running on WSL can be another hassle: depending on your X-server, things may or may not work smoothly. I still think that there should be some option to tune, native to ~/.jupyter/jupyter_notebook_config.py, that shall save us the trouble of setting up a WSL-booted Firefox browser.

@raghavven
Copy link

I first ran the command 'export DISPLAY=localhost:0.0' and then ran the following commands
'firefox' and '/usr/bin/firefox'. It gave me the following error for both.

"irefox
Failed to connect to Mir: Failed to connect to server socket: No such file or directory
Unable to init server: Broadway display type not supported: localhost:0.0
Error: cannot open display: localhost:0.0"

I understand , what you are saying. I should be able to simply copy past the jupyter notebook link on firefox or chrome and it should work. I am just unable to understand what is wrong.

Thanks.

@llinfeng
Copy link

@raghavven I suggest that you may start Googling around and testing different parameters for the DISPLAY variable. This is more of a WSL issue now. Sorry for not able to help further. With the listed settings, I have been able to set up a good number of WSL installations that has "GUI support" (via X-forwarding).

@raghavven
Copy link

@llinfeng IIinfeng

I understand, thanks for your help. really appreciate it.

@martin2384798
Copy link

@thomasaarholt When you set $BROWSER, beware that spaces in your path should translated to \ , otherwise it will not be recognised:
export BROWSER='/mnt/c/Program\ Files\ (x86)/Google/Chrome/Application/chrome.exe'
This should do the job.

@thangckt
Copy link

thangckt commented Aug 5, 2019

Dear @martin2384798

I do as you recommended, that
export BROWSER='/mnt/c/Program\ Files\ (x86)/Google/Chrome/Application/chrome.exe'

but Jupyter notebook aslo cannot launch Chrome. Do you have any other Ideas?

Thank

@martin2384798
Copy link

martin2384798 commented Aug 6, 2019

@thangckt Start jupyter notebook service by running jupyter notebook in WSL, then try visit 127.0.0.1:8888 in Chrome (8888 is the default port used by jupyter notebook service), will it show a webpage of jupyter notebook?

@thangckt
Copy link

thangckt commented Aug 6, 2019

@martin2384798 ... yes, it correctly opens jupyter notebook webpage. So how I can make such address (i.e. 127.0.0.1:8888) to be opened automatically by typing "jupyter notebook"?
Thank.

@martin2384798
Copy link

martin2384798 commented Aug 9, 2019 via email

@AEljarrat
Copy link

Hi @thomasaarholt !

I recently decided to try WSL and also wanted to solve this. My solution includes creating a "Jupyter Notebook here" button in my context menu, which basically points to a terminal of choice (I use cmder) and runs a jupyter_notebook.sh script therein.

There is still a caveat. Because of some permission misshap, the jupyter notebook will not work in some folders especially dear to windows, such as your user folder. It still works in subfolders.

I share the code below for those interested.

Best regards,
Alberto.

This is the Cmder task, which is added to the windows registry key command.

set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl /mnt/c/users/aeljarrat/test/jupyter_notebook_here.sh -cur_console:pm:/mnt

The jupyter_notebook_here.sh script will open a jupyter notebook from wsl. You want to save it in a file that wsl can access and chmod +x that file at the linux side. The script is:

#! /bin/bash

# I need to source conda
source ~/anaconda3/bin/activate base

# Find the interesting output in stderr 
mycmd='jupyter notebook --no-browser'
exec 3< <($mycmd 2>&1)
a=$(grep -o -m1 'http://localhost.*' <&3)
echo $a

# Use preferred browser here
/mnt/c/Program\ Files/Mozilla\ Firefox/firefox.exe "$a"

# This keeps the terminal alive as we get the rest of the output
cat <&3

You can also use this script to open a notebook from the windows side, for instance;

wsl jupyter_notebook_here.sh

@thomasaarholt
Copy link
Contributor Author

@AEljarrat Not sure if small world, or if we're just very vocal.
That's neat, thanks for the script!

@martin2384798 The main issue is that calling the jupyter notebook command opens a browser window with the file:///home/thomasaar/.local/share/jupyter/runtime/nbserver-5243-open.html path. Windows doesn't recognise the "file:/// prefix, nor does it know where the rest of the path is.

I'm tempted to suggest a change to the code so as to have the option of defaulting to open the IP path (localhost) or the nbserver html file. The launch_browser call is here in the code.

@salihyanikgonul
Copy link

What it works for me is as follows:
I first created an alias for chrome on bash on Ubuntu on Windows by typing:

alias chrome="/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe".

Then I configured jupyter_notebook_config.py file by adding:
c.NotebookApp.browser = u'/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe %s' line.

Then, I launch jupyter-notebook on bash and it launched a new chrome tab on http://localhost:8888/tree.

Hope it works for you too.

@martin2384798
Copy link

l just type jupyter notebook in WSL and manually open a new chrome tab in Windows to do so, but thanks @salihyanikgonul may be try this method next time.

@juankikushima
Copy link

What it works for me is as follows:
I first created an alias for chrome on bash on Ubuntu on Windows by typing:

alias chrome="/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe".

Then I configured jupyter_notebook_config.py file by adding:
c.NotebookApp.browser = u'/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe %s' line.

Then, I launch jupyter-notebook on bash and it launched a new chrome tab on http://localhost:8888/tree.

Hope it works for you too.
@salihyanikgonul
I tried that but the browser still opens on
file:///home/username/.local/share/jupyter/runtime/nbserver-4601-open.html
just like @thomasaarholt said.
How do you managed for the browser to open on http://localhost:8888/tree???

@EwFuture
Copy link

EwFuture commented Dec 5, 2019

What it works for me is as follows:
I first created an alias for chrome on bash on Ubuntu on Windows by typing:

alias chrome="/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe".

Then I configured jupyter_notebook_config.py file by adding:
c.NotebookApp.browser = u'/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe %s' line.

Then, I launch jupyter-notebook on bash and it launched a new chrome tab on http://localhost:8888/tree.

Hope it works for you too.

Chrome for me is installed on my User account instead of Program Files, so using the correct path, the solution worked very nicely. Thank you @salihyanikgonul

@yphillip
Copy link

yphillip commented Dec 6, 2019

@AEljarrat, your script worked like a charm for me. Thanks for sharing.

The only tweak I made was to use the wslview utility (https://github.com/wslutilities/wslu/wiki/wslview), which then just opens the jupyter notebook in the default browser of Windows:

# Use preferred browser here
wslview "$a"

@ollie-bell
Copy link

What it works for me is as follows:
I first created an alias for chrome on bash on Ubuntu on Windows by typing:
alias chrome="/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe".
Then I configured jupyter_notebook_config.py file by adding:
c.NotebookApp.browser = u'/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe %s' line.
Then, I launch jupyter-notebook on bash and it launched a new chrome tab on http://localhost:8888/tree.
Hope it works for you too.
@salihyanikgonul
I tried that but the browser still opens on
file:///home/username/.local/share/jupyter/runtime/nbserver-4601-open.html
just like @thomasaarholt said.
How do you managed for the browser to open on http://localhost:8888/tree???

@juankikushima I am having the same issue in that my browser will automatically open, but it will try and open on the file rather than the URL! Anyone got any ideas how to fix that @salihyanikgonul ?

@ollie-bell
Copy link

What it works for me is as follows:
I first created an alias for chrome on bash on Ubuntu on Windows by typing:
alias chrome="/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe".
Then I configured jupyter_notebook_config.py file by adding:
c.NotebookApp.browser = u'/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe %s' line.
Then, I launch jupyter-notebook on bash and it launched a new chrome tab on http://localhost:8888/tree.
Hope it works for you too.
@salihyanikgonul
I tried that but the browser still opens on
file:///home/username/.local/share/jupyter/runtime/nbserver-4601-open.html
just like @thomasaarholt said.
How do you managed for the browser to open on http://localhost:8888/tree???

@juankikushima I am having the same issue in that my browser will automatically open, but it will try and open on the file rather than the URL! Anyone got any ideas how to fix that @salihyanikgonul ?

I have found how to fix this - i..e to have jupyter notebook launch from WSL in a windows web browser. There is a setting in the jupyter_notebook_config.py to force notebook to launch using the URL, not a redirect file.

c.NotebookApp.use_redirect_file = False
(default is True)

If you have your browser environment variable set, then running 'jupyter notebook' should now open it with http://localhost:8888/tree instead of the redirect file by default.

@juankikushima
Copy link

What it works for me is as follows:
I first created an alias for chrome on bash on Ubuntu on Windows by typing:
alias chrome="/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe".
Then I configured jupyter_notebook_config.py file by adding:
c.NotebookApp.browser = u'/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe %s' line.
Then, I launch jupyter-notebook on bash and it launched a new chrome tab on http://localhost:8888/tree.
Hope it works for you too.
@salihyanikgonul
I tried that but the browser still opens on
file:///home/username/.local/share/jupyter/runtime/nbserver-4601-open.html
just like @thomasaarholt said.
How do you managed for the browser to open on http://localhost:8888/tree???

@juankikushima I am having the same issue in that my browser will automatically open, but it will try and open on the file rather than the URL! Anyone got any ideas how to fix that @salihyanikgonul ?

I have found how to fix this - i..e to have jupyter notebook launch from WSL in a windows web browser. There is a setting in the jupyter_notebook_config.py to force notebook to launch using the URL, not a redirect file.

c.NotebookApp.use_redirect_file = False
(default is True)

If you have your browser environment variable set, then running 'jupyter notebook' should now open it with http://localhost:8888/tree instead of the redirect file by default.

Hi @acse-ogb119 but I got this message when I try your suggestion:

Config option use_redirect_file not recognized by NotebookApp.

Do you know what I might be doing wrong?

@cmfcmf
Copy link

cmfcmf commented Dec 20, 2019

I have found how to fix this - i..e to have jupyter notebook launch from WSL in a windows web browser. There is a setting in the jupyter_notebook_config.py to force notebook to launch using the URL, not a redirect file.

c.NotebookApp.use_redirect_file = False
(default is True)

For reference, you can also set use_redirect_file via a command line argument.

jupyter notebook:

BROWSER=/mnt/c/path/to/firefox.exe jupyter notebook --NotebookApp.use_redirect_file=False

jupyter lab:

BROWSER=/mnt/c/path/to/firefox.exe jupyter-lab --LabApp.use_redirect_file=False

@ollie-bell
Copy link

What it works for me is as follows:
I first created an alias for chrome on bash on Ubuntu on Windows by typing:
alias chrome="/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe".
Then I configured jupyter_notebook_config.py file by adding:
c.NotebookApp.browser = u'/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe %s' line.
Then, I launch jupyter-notebook on bash and it launched a new chrome tab on http://localhost:8888/tree.
Hope it works for you too.
@salihyanikgonul
I tried that but the browser still opens on
file:///home/username/.local/share/jupyter/runtime/nbserver-4601-open.html
just like @thomasaarholt said.
How do you managed for the browser to open on http://localhost:8888/tree???

@juankikushima I am having the same issue in that my browser will automatically open, but it will try and open on the file rather than the URL! Anyone got any ideas how to fix that @salihyanikgonul ?

I have found how to fix this - i..e to have jupyter notebook launch from WSL in a windows web browser. There is a setting in the jupyter_notebook_config.py to force notebook to launch using the URL, not a redirect file.
c.NotebookApp.use_redirect_file = False
(default is True)
If you have your browser environment variable set, then running 'jupyter notebook' should now open it with http://localhost:8888/tree instead of the redirect file by default.

Hi @acse-ogb119 but I got this message when I try your suggestion:

Config option use_redirect_file not recognized by NotebookApp.

Do you know what I might be doing wrong?

Try using @cmfcmf 's suggestion, that also works for me and is neater! Note that I have my BROWSER environment variable set in .bashrc so do not need to preceed the command with BROWSER=...

Hope it works!

@Proxxy0
Copy link

Proxxy0 commented Jan 15, 2020

What it works for me is as follows:
I first created an alias for chrome on bash on Ubuntu on Windows by typing:
alias chrome="/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe".
Then I configured jupyter_notebook_config.py file by adding:
c.NotebookApp.browser = u'/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe %s' line.
Then, I launch jupyter-notebook on bash and it launched a new chrome tab on http://localhost:8888/tree.
Hope it works for you too.
@salihyanikgonul
I tried that but the browser still opens on
file:///home/username/.local/share/jupyter/runtime/nbserver-4601-open.html
just like @thomasaarholt said.
How do you managed for the browser to open on http://localhost:8888/tree???

@juankikushima I am having the same issue in that my browser will automatically open, but it will try and open on the file rather than the URL! Anyone got any ideas how to fix that @salihyanikgonul ?

I have found how to fix this - i..e to have jupyter notebook launch from WSL in a windows web browser. There is a setting in the jupyter_notebook_config.py to force notebook to launch using the URL, not a redirect file.
c.NotebookApp.use_redirect_file = False
(default is True)
If you have your browser environment variable set, then running 'jupyter notebook' should now open it with http://localhost:8888/tree instead of the redirect file by default.

Hi @acse-ogb119 but I got this message when I try your suggestion:
Config option use_redirect_file not recognized by NotebookApp.
Do you know what I might be doing wrong?

Try using @cmfcmf 's suggestion, that also works for me and is neater! Note that I have my BROWSER environment variable set in .bashrc so do not need to preceed the command with BROWSER=...

Hope it works!

I've tried this, and it still doesn't work. It seems like no matter how I try to use NotebookApp.use_redirect_file=False, it just simply doesn't work.

The terminal displays:
Config option 'use_redirect_file' not recognized by 'NotebookApp'.

Would appreciate help with this issue.

@ldeng-ustc
Copy link

ldeng-ustc commented Feb 6, 2020

@AEljarrat, your script worked like a charm for me. Thanks for sharing.

The only tweak I made was to use the wslview utility (https://github.com/wslutilities/wslu/wiki/wslview), which then just opens the jupyter notebook in the default browser of Windows:

# Use preferred browser here
wslview "$a"

wslview going to handling file:/// protocol in version 3.0.0 (wslu issue #66), after that, we can solve this problem just by update jupyter config:
c.NotebookApp.browser = 'wslview %s'
Before they finished, I write a script to handle it manually.
This script use wslpath to change unix path after file URI to windows path, then use wslview to open it. Set jupyter notebook browser to this script, it can open browser correctly in WSL.

#!/bin/bash
url=$1
if [ -n "$url" ] && expr match $url 'file://*'; then
    url="file://`wslpath -am ${url:7}`"
    echo "opening...\n$url"
fi
wslview "$url"

@52june
Copy link

52june commented Feb 7, 2020

What it works for me is as follows:
I first created an alias for chrome on bash on Ubuntu on Windows by typing:
alias chrome="/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe".
Then I configured jupyter_notebook_config.py file by adding:
c.NotebookApp.browser = u'/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe %s' line.
Then, I launch jupyter-notebook on bash and it launched a new chrome tab on http://localhost:8888/tree.
Hope it works for you too.
@salihyanikgonul
I tried that but the browser still opens on
file:///home/username/.local/share/jupyter/runtime/nbserver-4601-open.html
just like @thomasaarholt said.
How do you managed for the browser to open on http://localhost:8888/tree???

@juankikushima I am having the same issue in that my browser will automatically open, but it will try and open on the file rather than the URL! Anyone got any ideas how to fix that @salihyanikgonul ?

I have found how to fix this - i..e to have jupyter notebook launch from WSL in a windows web browser. There is a setting in the jupyter_notebook_config.py to force notebook to launch using the URL, not a redirect file.
c.NotebookApp.use_redirect_file = False
(default is True)
If you have your browser environment variable set, then running 'jupyter notebook' should now open it with http://localhost:8888/tree instead of the redirect file by default.

Hi @acse-ogb119 but I got this message when I try your suggestion:

Config option use_redirect_file not recognized by NotebookApp.

Do you know what I might be doing wrong?

Please upgrade your notebook version because that option requires notebook 6.0.2 or above. After upgrading, I could solve the problem that a redirect file is launched 😂

@martin2384798
Copy link

What it works for me is as follows:
I first created an alias for chrome on bash on Ubuntu on Windows by typing:

alias chrome="/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe".

Then I configured jupyter_notebook_config.py file by adding:
c.NotebookApp.browser = u'/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe %s' line.

Then, I launch jupyter-notebook on bash and it launched a new chrome tab on http://localhost:8888/tree.

Hope it works for you too.

Work good for me even without the alias, for opening jupyter lab on WSL with the new Edge browser on Windows. Much thanks!

@Apreche
Copy link

Apreche commented Mar 30, 2020

A combination of all of the advice above worked for me. I'm running Ubuntu 18.04 in WSL1. I'm launching jupyter notebook from a Python/Django project. Here are all the steps I followed:

  1. Make sure django-extensions, ipython, and jupyter are all installed in the Python environment.
  2. Add django-extensions to the INSTALLED_APPS of the project.
  3. Set the environment variable DJANGO_ALLOW_ASYNC_UNSAFE=true as per this tutorial - https://davit.tech/django-jupyter-notebook/ Don't do this in production, but it's fine for local dev.
  4. apt install wslu to get the wslview program installed.
  5. Set the environment variable BROWSER=wslview to make wslview the default Linux browser. I did this with an export statement in my bashrc.
  6. Generate a jupyter notebook config file using jupyter notebook --generate-config
  7. Set c.NotebookApp.use_redirect_file = False in the config file that was just generated.
  8. Start a new WSL shell and verify the environment variables are set with env.
  9. ./manage.py shell_plus --notebook and the notebook opens in my native default Windows browser. Chrome and Firefox both work. Success!

@thomasaarholt
Copy link
Contributor Author

Hi sachika. Please open a separate issue as your problem is unrelated to this one.

@MellowPhi
Copy link

What it works for me is as follows:
I first created an alias for chrome on bash on Ubuntu on Windows by typing:

alias chrome="/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe".

Then I configured jupyter_notebook_config.py file by adding:
c.NotebookApp.browser = u'/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe %s' line.

Then, I launch jupyter-notebook on bash and it launched a new chrome tab on http://localhost:8888/tree.

Hope it works for you too.

I didn't use the alias. Simply just these two and I can launch Jupyter Notebook from WSL.

c.NotebookApp.browser = u'/mnt/c/Program\ Files/BraveSoftware/Brave-Browser/Application/brave.exe %s'
c.NotebookApp.use_redirect_file = False

Cheers

@DaniBrew4
Copy link

DaniBrew4 commented Nov 6, 2020

@thomasaarholt When you set $BROWSER, beware that spaces in your path should translated to \ , otherwise it will not be recognized:
'export BROWSER='/mnt/c/Program\ Files\ (x86)/Google/Chrome/Application/chrome.exe'
This should do the job.
This should be the correct answer. It worked great and was easy to configure.
To clarify, just type 'nano .bashrc' and then paste:
'export BROWSER='/mnt/c/Program\ Files\ (x86)/Google/Chrome/Application/chrome.exe' at the bottom of the file.

@zhangfiona
Copy link

In jupyter lab 3.0.8, the jupyter_notebook_config.py generated by jupyter lab --generate-config has been changed. According to solutions from @salihyanikgonul and @acse-ogb119, it has subtle changes:
alias chrome="/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe" added to .zshrc or .bashrc file,
c.ServerApp.browser = u'/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe %s'
c.ServerApp.use_redirect_file = False added to jupyter_notebook_config.py file.

@vivekkumar7089
Copy link

What it works for me is as follows:
I first created an alias for chrome on bash on Ubuntu on Windows by typing:

alias chrome="/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe".

Then I configured jupyter_notebook_config.py file by adding:
c.NotebookApp.browser = u'/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe %s' line.

Then, I launch jupyter-notebook on bash and it launched a new chrome tab on http://localhost:8888/tree.

Hope it works for you too.

@salihyanikgonul I have tried this but getting the error

This site can’t be reached 
localhost refused to connect.

@vivekkumar7089
Copy link

What it works for me is as follows:
I first created an alias for chrome on bash on Ubuntu on Windows by typing:
alias chrome="/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe".
Then I configured jupyter_notebook_config.py file by adding:
c.NotebookApp.browser = u'/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe %s' line.
Then, I launch jupyter-notebook on bash and it launched a new chrome tab on http://localhost:8888/tree.
Hope it works for you too.

@salihyanikgonul I have tried this but getting the error

This site can’t be reached 
localhost refused to connect.

After updating conda to its newer version, it is working fine. Thanks, everyone!!

@logansdmi
Copy link

Hi I tried the following and it worked:

I set an alias to chrome.exe in my .bashrc file as above:
alias chrome="/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe"

I open my jupyter notebooks on localhost:8888 so I made another alias to open this page and run jupyter notebook. The webpage had to be opened first as after jupyter notebook is run it does not run the next command in the alias.
alias notebook="chrome http://localhost:8888/; jupyter notebook"

When I use the command notebook now it very satisfyingly opens the chrome tab with the notebook immediately.

@amzon-ex
Copy link

amzon-ex commented Oct 27, 2021

For me, just setting
c.NotebookApp.use_redirect_file = False
works, i.e. throws no error + opens in browser the notebook.

The jupyter configuration file (jupyter_notebook_config.py) in a section specifies:

## 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 environment variable to override it.
#  Default: ''
# c.NotebookApp.browser = ''

Since this uses the webbrowser module, it seems like the module handles the opening of the browser by default (MS Edge in my case).

@guodongxiaren
Copy link

I find a solution:
update ~/.jupyter/jupyter_notebook_config.py config and set c.NotebookApp.use_redirect_file = False
If there are not a jupyter_notebook_config.py in your Home Path, you should generate it first.

Generate config

 jupyter notebook --generate-config

then

vim ~/.jupyter/jupyter_notebook_config.py

find c.NotebookApp.use_redirect_file and change it's value to False

 c.NotebookApp.use_redirect_file = False

next, export BROWSER in your ~/.bashrc or ~/.zshrc. for example:

export BROWSER="/mnt/c/Users/guodongxiaren/AppData/Local/Google/Chrome/Application/chrome.exe"  

finally, just run jupyter-lab in your shell.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests