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实现账号密码输错三次即锁定功能简单示例

本文实例讲述了Python实现账号密码输错三次即锁定功能。分享给大家供大家参考,具体如下: 初学Python—1 #实现账号输错三次即锁定 user = "hubery" passw...

一个计算身份证号码校验位的Python小程序

S = Sum(Ai * Wi), i=0,.......16 (现在的身份证号码都是18位长,其中最后一位是校验位,15位的身份证号码好像不用了) Ai对应身份证号码,Wi则为用于加权...

介绍Python中的__future__模块

Python的每个新版本都会增加一些新的功能,或者对原来的功能作一些改动。有些改动是不兼容旧版本的,也就是在当前版本运行正常的代码,到下一个版本运行就可能不正常了。 从Python 2....

python使用wxpython开发简单记事本的方法

python使用wxpython开发简单记事本的方法

本文实例讲述了python使用wxpython开发简单记事本的方法。分享给大家供大家参考。具体分析如下: wxPython是Python编程语言的一个GUI工具箱。他使得Python程序...

Python多线程同步---文件读写控制方法

Python多线程同步---文件读写控制方法

1、实现文件读写的文件ltz_schedule_times.py #! /usr/bin/env python #coding=utf-8 import os def ReadTi...