473,395 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Detecting Python Installs from the Windows Registry

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

Jan 7 '06 #1
2 1979
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

Jan 9 '06 #2
Great, I'll work with this.

Thanks

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

Jan 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Pat Blair | last post by:
Sorry to anyone who read this post, but in case it's useful to anyone: Further experiments reveal that while a tuple comes back if you read a multi-line string, you set the value using a list (not...
1
by: John Taylor | last post by:
I want to visit each windows registry entry (or at least a large number of them) and lookup the value for each entry. I want to take a snapshot of registry entries before and after I install...
0
by: Bart Nessux | last post by:
for i in range(10000): try: n,v,t = EnumValue(open_key,i) # n == name of the registry object. # v == object's value. # t == object's type. print n,v,t except EnvironmentError: print "\nThere...
17
by: Paul Rubin | last post by:
Dumb question from a Windows ignoramus: I find myself needing to write a Python app (call it myapp.py) that uses tkinter, which as it happens has to be used under (ugh) Windows. That's Windows...
1
by: Gerard Marshall Vignes | last post by:
I was recently cautioned against storing an ADO.NET Connection String in the Windows Registry because access to the Windows Registry would be serialized and therefore impact scalability. I have...
3
by: Mark Findlay | last post by:
When programming reads of the Windows Registry, do the registry keys and values need to be localized for international use? For example, do I need to convert the key name...
8
by: mistral | last post by:
I need compile code written in Python. I use Windows 98SE. Should I download Python for Windows installer? http://www.python.org/ftp/python/2.4.3/python-2.4.3.msi Will the msi installer modify...
11
by: Unknown Hero | last post by:
Tim Golden wrote: The first link which points to the Python documentation for the _winreg module I already checked, even before coming here. I am wondering how I should do the loop I need (go...
1
by: Berco Beute | last post by:
After first trying to install the beta of Python 2.6 on my Windows XP 64-bit machine I finally succeeded installing 2.5.2. But I still have a some problem: Installing iPython, PIL, easy_install etc...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.