On Windows, you have to modify the file associations, for example via Right Click → Open with ...
→ Choose default program
or the Control Panel's Folder Settings. You can choose between multiple python installations by navigating to the python.exe you want via the Browse button:

Alternatively, you can change the association in a command shell by typing
ftype Python.File="C:\Python27\python.exe" "%1" %*
Note that this requires administrator rights. If UAC is enabled on your machine, right click cmd in the start menu and select Run as administrator
.
On freedesktop.org-compatible desktops, you can configure the association with xdg-mime
.
On debian-based distributions, you can change the default python with update-alternatives
. On all systems, you can also symlink the python in your path to the correct implementation, like this:
$ sudo ln -sf python2.7 /usr/bin/python
If the file is marked executable, it can also be executed directly from the command line or GUI if it starts with #!
and the name of the interpreter:
#!/usr/bin/env python
To choose a specific Python version just for your program, you can start your Python program with one of the following lines:
#!/usr/bin/env python2.7
#!/usr/bin/python2.7