473,574 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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...



Jan 7 '06 #1
2 1985
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_name s(reg_key):
index = 0
L = []
while True:
name = _winreg.EnumKey (reg_key, index)
except EnvironmentErro r:
index += 1
return L

def function_in_sea rch_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\pyth on\pythoncore'
L = []
for reg_hive in (_winreg.HKEY_L OCAL_MACHINE,
python_key = _winreg.OpenKey (reg_hive, python_path)
except EnvironmentErro r:
for version_name in get_subkey_name s(python_key):
key = _winreg.OpenKey (python_key, version_name)
modification_da te = _winreg.QueryIn foKey(key)[2]
install_path = _winreg.QueryVa lue(key, 'installpath')
L.append((modif ication_date, version_name, install_path))
return L

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



Jan 10 '06 #3

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

Similar topics

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 a tuple). That's sensible and I don't know why this didn't occur to me before I posted. Thanks -----Original Message----- From: Pat Blair
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 software or make changes to the system and see what changes were made to it. My code works some of the time, but other times it does not return any...
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 are", i, "registy objects under this key." break
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 XP if it makes any difference. I put a shortcut to myapp.py on the desktop and it shows up as a little green snake icon, which is really cool and...
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 been able to find reasons to not use the Registry for storing Connection Strings, but the reasons given seem to be security-related. Does anyone...
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 L"\\Software\\Microsoft\\Windows" into Japanese, Korean, etc., for use in those markets? Thanks experts!
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 registry or other system files? Does it possible install Python not touching registry and system files? thanks.
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 through HKEY_LOCAL_MACHINE and read one subkey at a time, if it contains this 'foo' then change it into 'moo'). As I already said, I am by no means...
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 fails saying that python.exe cannot be found (although I can start the python interpeter just fine). The problem is that python cannot be found in...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.