安装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的安装。

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

 

转载于:https://www.cnblogs.com/pinpin/p/9881459.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值