Python Version 2.7 required which was not found in the registry

Python Version 2.7 required which was not found in the registry

今天在安装PIL时候出现了这个错误,自己摸索了好久,也在网上搜索了好久,最后终于解决了,下面将大家用的方法整理一下,方便大家解决问题。
![Python Version 2.7 required which was not found in the registry(https://img-blog.csdn.net/20170220195639403?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc21hbGxmbHlpbmdwaWc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)

问题重现

  1. 在windows下安装 python 2.7 64bit,在安装时候选择的是“所有用户
  2. 下载的PIL是PIL 1.1.7 for python 2.7的windows安装包
  3. 在按钻过过程中出现了这个问题
  4. 如果你很急迫,可以跳过中间几个方法,直接看最后一个方法。

解决方案

官方解决方案

Adding Python Information to the Windows Registry
在PIL的官网上给出了一个script,用于解决python没有注册的问题,内容如下:

#
# script to register Python 2.0 or later for use with win32all
# and other extensions that require Python registry settings
#
# written by Joakim Löw for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/products/works/articles/regpy20.htm

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_LOCAL_MACHINE, regpath)
    except EnvironmentError:
        try:
            reg = CreateKey(HKEY_LOCAL_MACHINE, 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()

这个脚本的功能就是在注册表下HKEY_LOCAL_MACHINE\SOFTWARE\Python\Pythoncore\Python 2.7下新建两个项,一个是python 的安装路径PythonPath,一个是第三方库的安装路径InstallPath,并给出他们的值,官网上同时给出了删除这两个注册表项的代码:

def UnRegisterPy():
    try:
        reg = OpenKey(HKEY_LOCAL_MACHINE, regpath)
    except EnvironmentError:
        print "*** Python not registered?!"
        return
    try:
        DeleteKey(reg, installkey)
        DeleteKey(reg, pythonkey)
        DeleteKey(HKEY_LOCAL_MACHINE, regpath)
    except:
        print "*** Unable to un-register!"
    else:
        print "--- Python", version, "is no longer registered!"

注意这只是个函数,需要将它添加到上一个脚本中,并在main中调用。
有很多人使用这个方法就成功了。但是我没有成功,我给出的错误信息是:

*** Unable to register!
*** You probably have another Python installation!

也就是已经有这两个注册表项了。

博友给出的方案

CSDN上有博友给出了一个方案,我没有测试。但是根据评论很多人成功了。
Python Version 2.7 required which was not found in the registry 问题解决
下面的内容摘自他的博客,侵删。

Python的一些第三方库只到注册表的HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath路径下寻找Python。但是装好的64位Python在HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.7\InstallPath路径下建立Python的信息。所以,在cmd输入regedit然后将HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.7\InstallPath路径下的值,复制到HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath路径下,当然没有路径的话一定要新建起来。
然后就可以安装了。
本解决方案适用于安装numpy,SetupTools等只提供了32位安装包的库。
P.S
Python的功能很大程度上取决于第三方库,但是很多开发这并不喜欢提供64位版本。上面方法只是个参考,其实最靠谱的解决方案1、Python和第三方库都装成32位;2、把第三方库文件下载下来,重新编译。

我虽然没有用这个方法(太麻烦,而且要手动添加注册表),但是我找到了我安装失败的原因,就是我安装的python是64bit的,这才是问题的关键,PIL是32bit的,而我的python是64bit的,所以才会提示没有注册python.

最简单的解决办法

重装python,安装成32bit的即可。成功。

参考

Adding Python Information to the Windows Registry

Python Version 2.7 required which was not found in the registry 问题解决

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值