关于”python version 2.7 required,which was not found in the registry“的问题

来源:互联网 发布:2016淘宝官方活动 编辑:程序博客网 时间:2024/05/21 01:31

安装MySQL-python-1.2.5.win32-py2.7或者其它库时报如下问题:

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

解决办法,运行如下脚本即可:

#本脚本用于python注册脚本,便于安装python库不识别python版本之用import sysfrom _winreg import *#_winreg  python操作注册表的模块version = sys.version[:3]installpath = sys.prefixregpath = "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()
运行结果如下:

0 0
原创粉丝点击