Python 为什么bash(WSL)使用w3m作为它的&x27;默认浏览器是什么?

Python 为什么bash(WSL)使用w3m作为它的&x27;默认浏览器是什么?,python,bash,windows-10,python-webbrowser,w3m,Python,Bash,Windows 10,Python Webbrowser,W3m,Windows10上Ubuntu上的Bash用来打开终端内部的URL,而不是打开Chrome或Edge。如何让它启动Windows默认web浏览器 例如,下面的代码 webbrowser.open_new("http://www.youtube.com/watch?v=dQw4w9WgXcQ") 看起来像这样: 这与使用打开页面完全相同 w3m http://www.youtube.com/watch?v=dQw4w9WgXcQ 这是一个全新的Win 10安装,在我启用Bash(通过Lin

Windows10上Ubuntu上的Bash用来打开终端内部的URL,而不是打开Chrome或Edge。如何让它启动Windows默认web浏览器

例如,下面的代码

webbrowser.open_new("http://www.youtube.com/watch?v=dQw4w9WgXcQ")
看起来像这样:

这与使用打开页面完全相同

w3m http://www.youtube.com/watch?v=dQw4w9WgXcQ
这是一个全新的Win 10安装,在我启用Bash(通过Linux的Windows子系统)并完成以下操作之后:

$ 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
然而

给予

www-browser
只是
w3m
的另一个别名,为什么没有列出
windows-default

在此之前,在运行Git Bash的32位Windows 10机器上,相同的Python 2.7代码的功能与预期相同,因此我认为Python方面没有任何问题。

Easy Fix: 如果您正在运行当前Windows Insider预览慢速频道构建(#14986)附带的最新WSL和Ubuntu 16.04,那么这种简单的变通方法就可以奏效。您不必在后台运行xserver,您可以选择启动Windows浏览器

您只需在
~/.bashrc文件
中添加以下行即可(下面列出了Chrome的默认安装位置作为一个示例。请随意将地址放入所需的浏览器):

注意:在处理诸如空格或()之类的地址中的复杂字符时,必须使用“\”对其进行转义

更难(黑客)修复: 基本上,Windows Linux子系统(WSL)并不正式支持基于GUI的程序。但是,有一种解决方法可以使用xserver从WSL运行一些基于GUI的Linux程序,请参见此处:

如果这对您不起作用,您可能还需要设置BROWSER环境变量,这是我发现GUI hack时尝试执行的操作,请参见此处:

注意:

尽管这个“有效”,但它在启动时会抛出一些错误(下面的示例),只需等待,很快它就会在xserver窗口中启动。对于我的一个python项目,它停止了执行。为了解决这个问题,我可能会写一些错误处理。我仍然很想知道是否有人有一个更优雅的解决方案来解决老Windows10系统上的问题

Nathaniel@DESKTOP-NAGL0DJ:~$ libkmod: ERROR ../libkmod/libkmod-module.c:1619 kmod_module_new_from_loaded: could not open /proc/modules: No such file or directory
Error: could not get list of modules: No such file or directory
[144:144:0103/123322:FATAL:render_sandbox_host_linux.cc(40)] Check failed: 0 == shutdown(renderer_socket_, SHUT_RD). shutdown: Invalid argument
#0 0x7f41e1522a2e base::debug::StackTrace::StackTrace()
#1 0x7f41e153cf87 logging::LogMessage::~LogMessage()
#2 0x7f41e153d1a9 logging::ErrnoLogMessage::~ErrnoLogMessage()
#3 0x7f41df5ace45 content::RenderSandboxHostLinux::Init()
#4 0x7f41df36c65a content::BrowserMainLoop::EarlyInitialization()
#5 0x7f41df36f7ff <unknown>
#6 0x7f41df368e1d content::BrowserMain()
#7 0x7f41df2d73d4 <unknown>
#8 0x7f41df2d6611 content::ContentMain()
#9 0x7f41e1cf98e8 <unknown>
#10 0x7f41d4681f45 __libc_start_main
#11 0x7f41e1cf97ba <unknown>

Aborted (core dumped)
Sandbox: unexpected multithreading found; this prevents using namespace sandboxing.

(firefox:30): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
Nathaniel@DESKTOP-NAGL0DJ:~$libkmod:ERROR../libkmod/libkmod module.c:1619 kmod\u module\u new\u from\u loaded:无法打开/proc/modules:没有这样的文件或目录
错误:无法获取模块列表:没有此类文件或目录
[144:144:0103/123322:FATAL:render\u sandbox\u host\u linux.cc(40)]检查失败:0==关闭(renderer\u socket\u,SHUT\u RD)。关机:参数无效
#0 0x7F41E1522E2E基::调试::堆栈跟踪::堆栈跟踪()
#1 0x7f41e153cf87日志记录::LogMessage::~LogMessage()
#2 0x7f41e153d1a9日志记录::ErrnoLogMessage::~ErrnoLogMessage()
#3 0x7f41df5ace45内容::RenderSandboxHostLinux::Init()
#4 0x7f41df36c65a内容::BrowserMainLoop::早期初始化()
#5 0x7f41df36f7ff
#6 0x7f41df368e1d内容::BrowserMain()
#7 0x7f41df2d73d4
#8 0x7f41df2d6611内容::ContentMain()
#9 0x7f41e1cf98e8
#10 0x7f41d4681f45自由启动主
#11 0x7f41e1cf97ba
中止(堆芯转储)
沙盒:发现意外的多线程;这可以防止使用名称空间沙箱。
(firefox:30):GConf警告**:客户端未能连接到D-BUS守护程序:
没有收到答复。可能的原因包括:远程应用程序未发送回复、消息总线安全策略阻止了回复、回复超时过期或网络连接中断。

一个相关问题:“。对于firefox:
导出显示=:0
导出浏览器=/mnt/c/Program\Files/Mozilla\firefox/firefox.exe
一旦两个导出行位于.bashrc文件中,您实际上如何运行浏览器?我没有看到任何命令别名、符号链接或任何关于如何从WSL启动所选浏览器的内容
['www-browser', 'w3m']
export DISPLAY=:0
export BROWSER=/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe
Nathaniel@DESKTOP-NAGL0DJ:~$ libkmod: ERROR ../libkmod/libkmod-module.c:1619 kmod_module_new_from_loaded: could not open /proc/modules: No such file or directory
Error: could not get list of modules: No such file or directory
[144:144:0103/123322:FATAL:render_sandbox_host_linux.cc(40)] Check failed: 0 == shutdown(renderer_socket_, SHUT_RD). shutdown: Invalid argument
#0 0x7f41e1522a2e base::debug::StackTrace::StackTrace()
#1 0x7f41e153cf87 logging::LogMessage::~LogMessage()
#2 0x7f41e153d1a9 logging::ErrnoLogMessage::~ErrnoLogMessage()
#3 0x7f41df5ace45 content::RenderSandboxHostLinux::Init()
#4 0x7f41df36c65a content::BrowserMainLoop::EarlyInitialization()
#5 0x7f41df36f7ff <unknown>
#6 0x7f41df368e1d content::BrowserMain()
#7 0x7f41df2d73d4 <unknown>
#8 0x7f41df2d6611 content::ContentMain()
#9 0x7f41e1cf98e8 <unknown>
#10 0x7f41d4681f45 __libc_start_main
#11 0x7f41e1cf97ba <unknown>

Aborted (core dumped)
Sandbox: unexpected multithreading found; this prevents using namespace sandboxing.

(firefox:30): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.