首页 > 编程语言 > 详细

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

时间:2014-02-14 16:52:36      阅读:432      评论:0      收藏:0      [点我收藏+]

在安装pywin32时,提示报错:Python version 2.7 required, which was not found in the registry。在网上搜下了,识别不出注册表,解决办法如下:

新建一个register.py 文件,把一下代码贴进去

bubuko.com,布布扣
import sys 
  
from _winreg import * 
  
# tweak as necessary 
version = sys.version[:3] 
installpath = sys.prefix 
  
regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version) 
installkey = "InstallPath" 
pythonkey = "PythonPath" 
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % ( 
    installpath, installpath, installpath 
) 
  
def RegisterPy(): 
    try: 
        reg = OpenKey(HKEY_CURRENT_USER, regpath) 
    except EnvironmentError as e: 
        try: 
            reg = CreateKey(HKEY_CURRENT_USER, 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() 
bubuko.com,布布扣

然后命令行切换到脚本目录运行:python register.py 

显示:--- Python 2.7 is now registered!  则表示成功

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

原文:http://www.cnblogs.com/youxin/p/3548611.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!