码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-04-26 01:51:35      阅读:3593      评论:0      收藏:0      [点我收藏+]

标签:

当安装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.然后在直接运行安装文件即可

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

标签:

原文地址:http://www.cnblogs.com/cutd/p/5433428.html

(1)
(4)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!