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

yipeiwu_com6年前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通过TensorFLow进行线性模型训练原理与实现方法详解

Python通过TensorFLow进行线性模型训练原理与实现方法详解

本文实例讲述了Python通过TensorFLow进行线性模型训练原理与实现方法。分享给大家供大家参考,具体如下: 1、相关概念 例如要从一个线性分布的途中抽象出其y=kx+b的分布规律...

python类:class创建、数据方法属性及访问控制详解

python类:class创建、数据方法属性及访问控制详解

在Python中,可以通过class关键字定义自己的类,然后通过自定义的类对象类创建实例对象。 python中创建类 创建一个Student的类,并且实现了这个类的初始化函数”__ini...

21行Python代码实现拼写检查器

引入 大家在使用谷歌或者百度搜索时,输入搜索内容时,谷歌总是能提供非常好的拼写检查,比如你输入 speling,谷歌会马上返回 spelling。 下面是用21行python代码实现的一...

Python实现基于KNN算法的笔迹识别功能详解

Python实现基于KNN算法的笔迹识别功能详解

本文实例讲述了Python实现基于KNN算法的笔迹识别功能。分享给大家供大家参考,具体如下: 需要用到: Numpy库 Pandas库 手写识别数据 点击此处本站下载。...

关于pytorch多GPU训练实例与性能对比分析

关于pytorch多GPU训练实例与性能对比分析

以下实验是我在百度公司实习的时候做的,记录下来留个小经验。 多GPU训练 cifar10_97.23 使用 run.sh 文件开始训练 cifar10_97.50 使用 run.4GPU...