Normally I work with Ruby and I don’t have this issue thanks to some gems I have installed, but for Python I’m not sure how to handle this.
I’m on a Windows machine, and I develop with VS Code using WSL/Ubuntu.
A simple script such as
import webbrowser
webbrowser.open('https://inventwithpython.com/')
simply does nothing and returns False with no other information. I know this means it is failing to open the browser, and I suspect it is due to the subsystem not having access (or not knowing how to access) the default browser that is set for the Windows OS. The problem is that this is a bit out of the scope of what I know how to do.
I’ve found a workaround in the following way…
import subprocess
subprocess.run(["cmd.exe", "/c", "start", "https://inventwithpython.com/"])
However I’m guessing this code won’t work on all "normal" systems. I’d like to know if there’s some other workaround I can use that still uses the .open() method mentioned above.
2
Answers
Issue solved. I asked a former teacher of mine, and they gave me a few commands to run in the terminal that fixed the issue, which were the following:
Thanks Yann!
I tried that little function of webbrowser on a windows machine and it works, you might try reinstalling python on your machine.
If the error persist downgrade python.