Python version 2.7 required, which was not found in the registry

http://blog.csdn.net/zklth/article/details/8117207

 1 import sys
 2 
 3 from _winreg import *
 4 
 5 # tweak as necessary
 6 version = sys.version[:3]
 7 installpath = sys.prefix
 8 
 9 regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
10 installkey = "InstallPath"
11 pythonkey = "PythonPath"
12 pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
13     installpath, installpath, installpath
14 )
15 
16 
17 def RegisterPy():
18     try:
19         reg = OpenKey(HKEY_CURRENT_USER, regpath)
20     except EnvironmentError as e:
21         try:
22             reg = CreateKey(HKEY_CURRENT_USER, regpath)
23             SetValue(reg, installkey, REG_SZ, installpath)
24             SetValue(reg, pythonkey, REG_SZ, pythonpath)
25             CloseKey(reg)
26         except:
27             print "*** Unable to register!"
28             return
29         print "--- Python", version, "is now registered!"
30         return
31     if (QueryValue(reg, installkey) == installpath and
32                 QueryValue(reg, pythonkey) == pythonpath):
33         CloseKey(reg)
34         print "=== Python", version, "is already registered!"
35         return
36     CloseKey(reg)
37     print "*** Unable to register!"
38     print "*** You probably have another Python installation!"
39 
40 
41 if __name__ == "__main__":
42     RegisterPy()

 


posted @ 2017-08-25 13:45  沈晓桐  阅读(184)  评论(0编辑  收藏  举报