1. 检查一下注册表是否存在python其它版本的信息
方法:
1)在命令行中输入regedit打开注册表
2)在HKEY_CURRENT_USER\Software中找一下是否存在python注册信息,如果存在,检查一下是否是python27版本,且是否包含下面两个节点
再检查一下其对于的安装路径是否正确。如果不知道如何检查,可以把python节点信息右击选择删除。如果python注册信息不存在,这里就不用操作了。
2.新建register.py文件,复制如下代码保存在D盘根目录下,cmd命令行运行 python register.py,当输出“python 2.7 is already registered”就ok了
(python27使用正常,无需修改任何内容)
1 # 2 # script to register Python 2.0 or later for use with win32all 3 # and other extensions that require Python registry settings 4 # 5 # written by Joakim Loew for Secret Labs AB / PythonWare 6 # 7 # source: 8 # http://www.pythonware.com/products/works/articles/regpy20.htm 9 # 10 # modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html 11 12 import sys 13 14 from _winreg import * 15 16 # tweak as necessary 17 version = sys.version[:3] 18 installpath = sys.prefix 19 20 regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version) 21 installkey = "InstallPath" 22 pythonkey = "PythonPath" 23 pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % ( 24 installpath, installpath, installpath 25 ) 26 27 28 def RegisterPy(): 29 try: 30 reg = OpenKey(HKEY_CURRENT_USER, regpath) 31 except EnvironmentError as e: 32 try: 33 reg = CreateKey(HKEY_CURRENT_USER, regpath) 34 SetValue(reg, installkey, REG_SZ, installpath) 35 SetValue(reg, pythonkey, REG_SZ, pythonpath) 36 CloseKey(reg) 37 except: 38 print "*** Unable to register!" 39 return 40 print "--- Python", version, "is now registered!" 41 return 42 if (QueryValue(reg, installkey) == installpath and 43 QueryValue(reg, pythonkey) == pythonpath): 44 CloseKey(reg) 45 print "=== Python", version, "is already registered!" 46 return 47 CloseKey(reg) 48 print "*** Unable to register!" 49 print "*** You probably have another Python installation!" 50 51 52 if __name__ == "__main__": 53 RegisterPy()
3.执行后再检查一下注册表。python27的注册信息已经存在了
4. 再次安装pywin32-220.win32-py2.7.exe,结果安装成功