安装Python第三方模块遇到Python version 2.7 required, which was not foundin the registry的问题
最近在学习Python,当需要安装到一些第三方模块的时候发现出现了
“Python version 2.7 required, which was not foundin the registry”
的问题,如下图:
网上搜了下,原来是因为安装Python的时候使用了all users可用的选项,如果选择仅本用户可用便不会出现这个问题,但是难道要重装?于是又找到了方法,便是将以下脚本保存,并运行,即可顺利解决问题,脚本代码如下(发现51cto的代码块不能缩进,已将代码放附件了):
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
## script to register Python 2.0 or later for use with win32all# and other extensions that require Python registry settings## written by Joakim Loew for Secret Labs AB / PythonWare## source:# http://www.pythonware.com/products/works/articles/regpy20.htm## modified by Valentine Gogichashvili as described in http://www.mail-archive.com/[email protected]/msg10512.htmlimport sys
from _winreg import *
# tweak as necessaryversion = 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!"
returnprint "--- Python", version, "is now registered!"
returnif (QueryValue(reg, installkey) == installpath and
QueryValue(reg, pythonkey) == pythonpath):
CloseKey(reg)print "=== Python", version, "is already registered!"
returnCloseKey(reg)print "*** Unable to register!"
print "*** You probably have another Python installation!"
if __name__ == "__main__":
RegisterPy() |
将以上代码保存脚本register.py后,在命令行下进入对应目录下运行命令“Python register.py”
安装顺利进行
附件:http://down.51cto.com/data/2364250
本文转自 leyex 51CTO博客,原文链接:http://blog.51cto.com/leyex/1389274