在注册表中无Python3.5安装路径的情况下安装pywin32-

当安装pywin32出现Python Version 3.5 required which was not found in the registry的时候表面注册表中没有Python3.5的安装路径。  
我出现这种情况是因为我直接用的Anaconda所以注册表没有注册  
解决办法:  
1. 先在注册表中写入Python3.5的安装路径。我在网上找到了注册表注册的代码贴出来供大家使用。 

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() 

2.然后在直接运行安装文件即可

文章来自:http://www.cnblogs.com/cutd/p/5433428.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3