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

来源:互联网 发布:软件测试加班图片 编辑:程序博客网 时间:2024/06/06 04:49

解决方案:

原因是缺少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 necessaryversion = 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

1 0