'Why is bash (WSL) using w3m as it's default browser?

Bash on Ubuntu on Windows 10 is using w3m to open URLs inside the terminal instead of opening Chrome or Edge. How can I get it to launch the Windows default web browser?

For example, the following code

webbrowser.open_new("http://www.youtube.com/watch?v=dQw4w9WgXcQ")

looks like this:

webpage displayed as text in terminal

This is exactly the same as opening the page with

w3m http://www.youtube.com/watch?v=dQw4w9WgXcQ

This is on a fresh Win 10 installation and after I've enabled Bash (via the Windows Subsystem for Linux) and done the following:

$ sudo apt update && sudo apt upgrade && sudo apt dist-upgrade
$ sudo apt install build-essential
$ sudo apt install python-pip python-dev
$ sudo pip install --upgrade pip

Yet

print webbrowser._tryorder

gives

['www-browser', 'w3m']

www-browser is just another alias for w3m, why is windows-default not listed?

Previously, The same Python 2.7 code functioned as expected on a 32-bit Windows 10 machine running Git-Bash, so I don't think there are any issues with the python side of things.



Solution 1:[1]

Install wslu (A collection of utilities for WSL) https://github.com/wslutilities/wslu#feature and then add these two lines to your shell's RC file, e.g. .bashrc or .zshrc:

export DISPLAY=:0
export BROWSER=/usr/bin/wslview

Run the two commands from your shell to make it work right away or log out and back in again.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marko V