简体   繁体   中英

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.

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.
But when I run the code with .ipynb file, it will pop out the webpage.

CODE :代码

What can I do to make the code run in vscode?

The same problem with me, I think this is related to VSCode settings. I've tried to use the terminal inside VSCode by typing " python <filename.py> ", and it worked well. It is not the direct solution, but it may help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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