Skip to content

Instantly share code, notes, and snippets.

@rukeba
Created January 27, 2011 07:53
Show Gist options
  • Save rukeba/798218 to your computer and use it in GitHub Desktop.
Save rukeba/798218 to your computer and use it in GitHub Desktop.
Switch python version between multiple python installations
""" http://nedbatchelder.com/blog/200810/switching_python_versions_on_windows.html
Change the .py file extension to point to a different
Python installation.
"""
import _winreg as reg
import sys
pydir = sys.argv[1]
todo = [
('Python.CompiledFile\DefaultIcon',
'PYDIR\\pyc.ico'),
('Python.CompiledFile\shell\open\command',
'"PYDIR\\python.exe" "%1" %*'),
('Python.File\DefaultIcon',
'PYDIR\\py.ico'),
('Python.File\shell\open\command',
'"PYDIR\\python.exe" "%1" %*'),
('Python.NoConFile\DefaultIcon',
'PYDIR\\py.ico'),
('Python.NoConFile\shell\open\command',
'"PYDIR\\pythonw.exe" "%1" %*'),
]
classes_root = reg.OpenKey(reg.HKEY_CLASSES_ROOT, "")
for path, value in todo:
print path, value
key = reg.OpenKey(classes_root, path, 0, reg.KEY_SET_VALUE)
reg.SetValue(key, '', reg.REG_SZ, value.replace('PYDIR', pydir))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment