Bentley4
Bentley4

Reputation: 11028

Why can't I open a webbrowser with webbrowser.open("www.python.org") on Cygwin?

>>> webbrowser.open("www.python.org")
False

Is there any other way to get the same functionality of that function in Cygwin?

Upvotes: 0

Views: 2751

Answers (2)

Michael Hoffman
Michael Hoffman

Reputation: 34324

export BROWSER=cygstart

before starting Python. Then it should work.

Upvotes: 13

tricasse
tricasse

Reputation: 1417

Launching a web browser from Cygwin can be done through

cygstart "http://www.google.com"

where google.com is your desired URL.

cygstart launches the default windows program for a path, so this way you get the user’s preferred web browser.

So in Python under Cygwin you might just:

from subprocess import call
call(["cygstart", "http://www.google.com"])

or try another option from here to run the Python-external command.

If it's not just a one-off script you are writing for your own use, you should use platform.system to use the above on Cygwin, and webbrowser.open on other platforms.

Upvotes: 2

Related Questions