Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Detecting Python Installs from the Windows Registry

1 view
Skip to first unread message

Fuzzyman

unread,
Jan 6, 2006, 9:01:17 AM1/6/06
to
Hello all,

I'm creating a py2exe program (for Windows) that needs to detect all
version of Python installed on the machine.

Because it is running under py2exe it doesn't have access to the Python
environment variables.

Does anyone know how to use _winreg to get path information (location
of install) for all versions of Python installed (and also which is the
most recent) ?

Googling the group didn't quickly turn up the answer, and I thought
*someone* was likely to know easily...

Thanks

Fuzzyman
http://www.voidspace.org.uk/python/idnex.shtml

Ziga Seilnacht

unread,
Jan 9, 2006, 5:20:31 AM1/9/06
to
Fuzzyman wrote:

> Does anyone know how to use _winreg to get path information (location
> of install) for all versions of Python installed (and also which is the
> most recent) ?

This should probably work:

import _winreg

def get_subkey_names(reg_key):
index = 0
L = []
while True:
try:
name = _winreg.EnumKey(reg_key, index)
except EnvironmentError:
break
index += 1
L.append(name)
return L

def function_in_search_of_a_name():
"""
Return a list with info about installed versions of Python.

Each version in the list is represented as a tuple with 3 items:

0 A long integer giving when the key for this version was last
modified as 100's of nanoseconds since Jan 1, 1600.
1 A string with major and minor version number e.g '2.4'.
2 A string of the absolute path to the installation directory.
"""
python_path = r'software\python\pythoncore'
L = []
for reg_hive in (_winreg.HKEY_LOCAL_MACHINE,
_winreg.HKEY_CURRENT_USER):
try:
python_key = _winreg.OpenKey(reg_hive, python_path)
except EnvironmentError:
continue
for version_name in get_subkey_names(python_key):
key = _winreg.OpenKey(python_key, version_name)
modification_date = _winreg.QueryInfoKey(key)[2]
install_path = _winreg.QueryValue(key, 'installpath')
L.append((modification_date, version_name, install_path))
return L

Fuzzyman

unread,
Jan 10, 2006, 3:59:15 AM1/10/06
to
Great, I'll work with this.

Thanks

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

0 new messages