Documente Academic
Documente Profesional
Documente Cultură
htm
Some Python distributions add information to the Windows registry when installed. This
information is used by certain tools, such as the win32all installer and Windows
installers generated by the distutils (dead link) package.
The following script registers the current interpreter. The script should work for Python
2.0 and later.
Note that there can be only one registered interpreter for each major Python release (e.g.
2.0, 2.1, 2,2 etc).
import sys
# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix
def RegisterPy():
try:
reg = OpenKey(HKEY_LOCAL_MACHINE, regpath)
except EnvironmentError:
try:
reg = CreateKey(HKEY_LOCAL_MACHINE, regpath)
SetValue(reg, installkey, REG_SZ, installpath)
SetValue(reg, pythonkey, REG_SZ, pythonpath)
CloseKey(reg)
except:
print "*** Unable to register!"
return
print "--- Python", version, "is now registered!"
return
if (QueryValue(reg, installkey) == installpath and
QueryValue(reg, pythonkey) == pythonpath):
CloseKey(reg)
print "=== Python", version, "is already registered!"
return
CloseKey(reg)
print "*** Unable to register!"
print "*** You probably have another Python installation!"
if __name__ == "__main__":
RegisterPy()
(To download, triple-click on the first line to select the entire script, and copy the text
into your favourite text editor.)
If you need to reverse the above, you can add the following function to the script (code
provided by Martin Lamar):