Make sure the filename extension .py
is associated with the appropriate python.exe
. Similarly, .pyw
should be associated with pythonw.exe
(this is a version of the Python interpreter that doesn't show a terminal window, suitable for use with Python GUI scripts).
The Python for Windows installer does this, so you usually won't have to mess with it unless you have multiple Python installs on your machine. If you do need to change the association, this can be done by right-clicking a .py
file, choosing Properties, and clicking the Change button next to "Opens with."
Windows ignores the shebang line, so there is no way (short of Cygwin) to have different scripts use different versions of Python by changing the shebang. You could use a different extension (e.g. .py3
for Python 3 scripts) and associate that with C:\Python31\python.exe
-- but that will break the script's ability to be imported as a module (Python expects the .py
extension), so use it carefully. Better practice is probably to just specify the desired python.exe
directly on the command line.