您的位置:首页 > 编程语言 > Python开发

报错 no module named win32api 的解决方案 以及python添加注册表方法

2015-12-31 09:55 661 查看


解决方案:

原因是缺少win32,到 http://sourceforge.net/projects/pywin32/files/

找到对应的版本进行下载,直接安装即可

window下,python安装两个版本,其中一个版本的注册表会被覆盖。要执行下面的脚本来添加测试表
#
# script to register Python 2.0 or later for use with win32all
# and other extensions that require Python registry settings
#
# written by Joakim Loew for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/products/works/articles/regpy20.htm #
# modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html 
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!"

if __name__ == "__main__":
RegisterPy()


Windows 7 64位下安装了 Python 的64位安装包,再安装其他预编译的Library就会有找不到Python的错误。 应该是有些Key没有加入到注册表中,需要运行下面的脚本修正。

该脚本用于python2.x,要注册python3.x版本,要修改

from _winreg import *
from winreg import *
原因是_winreg 改成了winreg




来源:http://blog.csdn.net/olanlanxiari/article/details/48196255

来源:http://www.cnblogs.com/min0208/archive/2012/05/24/2515584.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: