修复 Python version 2.6 required, which was not found in the registry.

这里参考了一篇博客 http://sinolog.it/?p=1288

如下:

原文地址:http://sinolog.it/?p=1288

Portable Python是可移植的Python开发环境,它允许同一个系统环境下并存多个版本且相互独立的Python开发环境,也适合放在移动存储设备中作为一个完备的的、便携的开发环境,这两个特点对开发人员非常有用。Portable Python集成了wxPythondjangoPyGame等一批常用的Python框架和模块,甚至内含了PyScripterSPE这两个Python的IDE,这使得Portable Python自解压到硬盘上开始就是一个完备的Python开发环境!

但是由于是可移植的,Portable Python并不会像Python官方的Windows平台安装程序一样在安装时往注册表中写入相关信息。同时,一些工具的安装或运行需要读取注册表中的Python信息,比如win32all安装程序和使用distutils包制作的安装程序。SQLite的Python移植版PySQLite的Windows平台安装程序就是使用distutils制作的,我在安装适用于Python 2.6的PySQLite到Portable Python时就因收到"Python version 2.6 required, which was not found in the registry."的错误而失败。

这里提供了解决办法,首先,将下面的代码复制并保存为一个Python文件(比如registerpython.py):

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/python
# -*- encoding: utf-8 -*-
#
# script to register Python 2.0 or later for use with win32all
# and other extensions that require Python registry settings
#
# written by Joakim Löw for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/products/works/articles/regpy20.htm
 
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_LOCAL_MACHINE, regpath)
    except EnvironmentError:
        try:
            reg = CreateKey(HKEY_LOCAL_MACHINE, 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!"
 
def UnRegisterPy():
    try:
        reg = OpenKey(HKEY_LOCAL_MACHINE, regpath)
    except EnvironmentError:
        print "*** Python not registered?!"
        return
    try:
        DeleteKey(reg, installkey)
        DeleteKey(reg, pythonkey)
        DeleteKey(HKEY_LOCAL_MACHINE, regpath)
    except:
        print "*** Unable to un-register!"
    else:
        print "--- Python", version, "is no longer registered!"
 
if __name__ == "__main__":
    # Register python's distribution
    RegisterPy()
    # If you want to unregister python's distribution, just comment the upper line and uncomment the following line
    #UnRegisterPy()

 

然后在Windows的cmd.exe中使用Portable Python的python.exe执行此脚本,例如我这里是:

D:\PortablePython1.1py2.6.1\App\python.exe D:\registerpython.py

执行后,正常情况下应该可以成功向注册表中写入相关信息,此时再安装PySQLite或其它依赖注册表中Python安装信息的程序就正常了。安装后的PySQLite已经不需要注册表,如果希望删除注册表中的信息,可以根据上面代码中的注释的说明,将"RegisterPy()"这一行注释掉,而去掉"UnRegisterPy()"前面的注释符号,然后再执行即可。


 

但是在安装jpype的时候,还是会报错,找到了这里的一个方案:http://stackoverflow.com/questions/3008509/python-version-2-6-required-which-was-not-found-in-the-registry

他是这么说的:

I realize this question is a year old - but I thought I would contribute one additional bit of info in case anyone else is Googling for this answer.

The issue only crops up on Win7 64-bit when you install Python "for all users". If you install it "for just me", you should not receive these errors. It seems that a lot of installers only look under HKEY_CURRENT_USER for the required registry settings, and not under HKEY_LOCAL_MACHINE. The page linked by APC gives details on how to manually copy the settings to HKEY_CURRENT_USER.

原来是win7 64位的电脑,在安装python时,如果选择只为当前用户,是没问题的,如果选择所有用户,那问题就是我所遇到的,ok,既然知道了这个问题,那么就好办了,我改了一下上面的python代码,大家可以参考附件

posted @ 2011-10-27 17:18  rickxu  阅读(2599)  评论(1编辑  收藏  举报