简体   繁体   English

Python webbrowser.open() 在 VScode 中不起作用(已尝试两种环境)

[英]Python webbrowser.open() is not working in VScode (already try two environment )

I'm trying to use the python webbrowser.open() to open a webpage, the code run perfectly, did not has any error in the terminal, but no webpage has pop out.我正在尝试使用python webbrowser.open()打开网页,代码运行完美,终端没有任何错误,但没有弹出网页。

import webbrowser
urlstr='https://www.twse.com.tw'
path=r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe "
webbrowser.register('google chrome',None,webbrowser.BackgroundBrowser(path))
webbrowser.get('google chrome').open(urlstr,new=1,autoraise=True)

终端

I tried Python 3.9.2 64-bit and Python 3.8.8 64-bit('base':conda) two environment but have same results.我尝试了 Python 3.9.2 64-bit 和 Python 3.8.8 64-bit('base':conda) 两个环境,但结果相同。
But when I run the code with .ipynb file, it will pop out the webpage.但是当我用 .ipynb 文件运行代码时,它会弹出网页。

CODE :代码 :代码

What can I do to make the code run in vscode?我该怎么做才能使代码在 vscode 中运行?

The same problem with me, I think this is related to VSCode settings.和我一样的问题,我认为这与VSCode设置有关。 I've tried to use the terminal inside VSCode by typing " python <filename.py> ", and it worked well.我尝试通过键入“ python <filename.py> ”在 VSCode 中使用终端,它运行良好。 It is not the direct solution, but it may help.这不是直接的解决方案,但可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM