Python version 2.7 required, which was not found in the registry

yipeiwu_com5年前Python基础

安装PIL库的时候,直接提示:Python version 2.7 required, which was not found in the registry。
如图:

大意是说找不到注册表,网上搜索解决方案。

新建一个register.py文件写入代码:

复制代码 代码如下:

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_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!"
            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!"

启动命令切到register.py文件目录下执行:

重新安装PIL,错误解决,安装成功。

如果是win7 64位的用户在安装Python 32位程序时,如果选择只为当前用户,以上问题不会出现。如果选择所有用户,就试着使用以上方法解决。

提示其它版本解决方法类似。

相关文章

python 寻找list中最大元素对应的索引方法

如下所示: aa = [1,2,3,4,5] aa.index(max(aa)) 如果aa是numpy数组: aa = numpy.array([1,2,3,4,5]) 先...

Python中实现三目运算的方法

C语言中三目运算符 复制代码 代码如下:    expression ?expr1:expr2;  //expression 为真则取表达式expr...

Python3日期与时间戳转换的几种方法详解

日期和时间的相互转换可以利用Python内置模块 time 和 datetime 完成,且有多种方法供我们选择,当然转换时我们可以直接利用当前时间或指定的字符串格式的时间格式。 获取当前...

python一键升级所有pip package的方法

pip_ungrade_all.py代码如下: # -*- coding: utf-8 -*- import pip from subprocess import call f...

python SQLAlchemy 中的Engine详解

python SQLAlchemy 中的Engine详解

先看这张图,这是从官方网站扒下来的。 Engine 翻译过来就是引擎的意思,汽车通过引擎来驱动,而 SQLAlchemy 是通过 Engine 来驱动,Engine 维护了一个连接池(...