python修复不了_修复 Python version 2.6 required, which was not found in the registry.

如下:

Portable Python是可移植的Python开发环境,它允许同一个系统环境下并存多个版本且相互独立的Python开发环境,也适合放在移动存储设备中作为一个完备的的、便携的开发环境,这两个特点对开发人员非常有用。Portable Python集成了wxPython、django、PyGame等一批常用的Python框架和模块,甚至内含了PyScripter、SPE这两个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):

#!/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()"前面的注释符号,然后再执行即可。

他是这么说的:

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代码,大家可以参考附件

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值