473,769 Members | 6,034 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...

Thanks

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

Jan 7 '06 #1
2 1994
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:
try:
name = _winreg.EnumKey (reg_key, index)
except EnvironmentErro r:
break
index += 1
L.append(name)
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,
_winreg.HKEY_CU RRENT_USER):
try:
python_key = _winreg.OpenKey (reg_hive, python_path)
except EnvironmentErro r:
continue
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.

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
1980
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
1
1667
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 data for some paths/keys when it appears to have data according to the regedit.exe program, on...
0
1905
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
17
3875
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 Pythonic. When I double click the icon, the app launches just fine and the tkinter interface does...
1
1975
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 know if there are performance-related reasons for NOT storing Connection Strings in the Windows...
3
2367
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!
8
1992
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.
11
7552
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 an expert in Python (heck, I learned the basics only a month ago). However, I am willing to learn.
1
5445
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 the registry. I tried Effbot's solution of adding Python to the registry, but that doesn't help: ...
0
10216
Oralloy
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8873
agi2029
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5309
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
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
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.