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

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

相关文章

numpy 返回函数的上三角矩阵实例

numpy 返回函数的上三角矩阵 np.triu() matrix2=np.triu(matrix1) numpy.triu(m, k=0)[source] Upper tri...

python中requests小技巧

python中requests小技巧

关于  Python requests ,在使用中,总结了一些小技巧把,记录下。 1:保持请求之间的Cookies,我们可以这样做。 2:请求时,会加上headers,一般我...

在cmd中运行.py文件: python的操作步骤

1 打开cmd, 不改变运行的目录: 输入python 空格  调试好的python文件路径 或者python 空格  将python文件拖入cmd中 2 打开cmd...

Python使用sorted排序的方法小结

Python使用sorted排序的方法小结

本文实例讲述了Python使用sorted排序的方法。分享给大家供大家参考,具体如下: # 例1. 按照元素出现的次数来排序 seq = [2,4,3,1,2,2,3] # 按次数排...

在Python中用split()方法分割字符串的使用介绍

split()方法返回的字符串中的所有单词的列表,使用str作为分隔符(如果在未指定的所有空格分割),可选择限当前分割为数量num。 语法 以下是split()方法的语法: str....