设为首页 收藏本站
查看: 1068|回复: 0

[经验分享] 修复 Python version 2.6 required, which was not found in the registry.

[复制链接]

尚未签到

发表于 2015-4-23 06:02:07 | 显示全部楼层 |阅读模式
  这里参考了一篇博客 http://sinolog.it/?p=1288
  如下:
  原文地址:http://sinolog.it/?p=1288
  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):
  




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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-59701-1-1.html 上篇帖子: ruby/python/java全覆盖的Selenium-Webdriver系列教程(2)————浏览器的简单操作 下篇帖子: 笔试测试开发题三道(python)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表