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位程序时,如果选择只为当前用户,以上问题不会出现。如果选择所有用户,就试着使用以上方法解决。

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

相关文章

对Django url的几种使用方式详解

利用Django开发网站,可以设计出非常优美的url规则,如果url的匹配规则(包含正则表达式)组织得比较好,view的结构就会比较清晰,比较容易维护。 最简单的形式 <cod...

python的继承知识点总结

python的继承知识点总结

python继承,python丰富的类因为继承而变得多姿多彩,如果语言不支持继承,那么类就没什么优势。 1、首先我们来定义两个类 一个dog类,一个bird类class Dog: &nb...

python 读取目录下csv文件并绘制曲线v111的方法

实例如下: # -*- coding: utf-8 -*- """ Spyder Editor This temporary script file is located here:...

Python 内置函数进制转换的用法(十进制转二进制、八进制、十六进制)

使用Python内置函数:bin()、oct()、int()、hex()可实现进制转换。 先看Python官方文档中对这几个内置函数的描述: bin(x) Convert an inte...

Python序列操作之进阶篇

简介 Python 的序列(sequence)通常指一个可迭代的容器,容器中可以存放任意类型的元素。列表和元组这两种数据类型是最常被用到的序列,python内建序列有六种,除了刚刚有说过...