安装pywin32出现--Python version 3.x required, which was not found in the registry

这两天安装pywin32时出现了这个问题

双击.exe文件进入安装界面,然后点击下一步,它会自动定位你的python安装在什么地方,但是我的安装过程中未自动定位到python安装位置,并显示显示:

安装pywin32出现--Python version 3.6 required, which was not found in the registry

百度了好久,就执行个python脚本即可解决

 

1、新建一个register.py文件(我将其放在pywin32同一个文件下),双击打开

python3将以下代码粘贴并保存

 1 from __future__ import print_function
 2  
 3  
 4 import sys
 5  
 6 try:
 7     from winreg import *
 8 except ImportError:
 9     from _winreg import *
10  
11 # tweak as necessary
12 version = sys.version[:3]
13 installpath = sys.prefix
14  
15 regpath = "SOFTWARE\\Python\\Pythoncore\\{0}\\".format(version)
16 installkey = "InstallPath"
17 pythonkey = "PythonPath"
18 pythonpath = "{0};{1}\\Lib\\;{2}\\DLLs\\".format(
19     installpath, installpath, installpath)
20  
21  
22 def RegisterPy():
23     try:
24         reg = OpenKey(HKEY_CURRENT_USER, regpath)
25     except EnvironmentError as e:
26         try:
27             reg = CreateKey(HKEY_CURRENT_USER, regpath)
28             SetValue(reg, installkey, REG_SZ, installpath)
29             SetValue(reg, pythonkey, REG_SZ, pythonpath)
30             CloseKey(reg)
31         except:
32             print("*** Unable to register!")
33             return
34         print("--- Python", version, "is now registered!")
35         return
36     if (QueryValue(reg, installkey) == installpath and
37         QueryValue(reg, pythonkey) == pythonpath):
38         CloseKey(reg)
39         print("=== Python", version, "is already registered!")
40         return
41     CloseKey(reg)
42     print("*** Unable to register!")
43     print("*** You probably have another Python installation!")
44  
45 if __name__ == "__main__":
46     RegisterPy()

2、保存之后进入cmd,切换到存储该py文件的目录,执行python registed.py即可重新运行exe文件进行pywin32的安装。

成功时的界面:然后点击下一步即可

 

posted @ 2018-10-31 10:17  阳光宝贝-沐沐  阅读(999)  评论(1编辑  收藏  举报