python:win32com和cx_Freeze-错误 [英] python: win32com and cx_Freeze - error

查看:61
本文介绍了python:win32com和cx_Freeze-错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用cx_Freeze编译Python 3.3脚本。
该脚本使用win32com.client控制 MediaMonkey 。当我直接运行它时,这很完美。但是,当我编译它时,它会引发此异常。

I'm trying to compile a Python 3.3 script using cx_Freeze. The script uses win32com.client to control MediaMonkey. This works perfect when I directly run it. But when I compile it, it throws this exception.

Traceback (most recent call last):
  File "O:\Python\3\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 27, in <module>
    exec(code, m.__dict__)
  File "test.py", line 6, in <module>
    sdb = win32com.client.DispatchWithEvents("SongsDB.SDBApplication", MMEventHandler)
  File "O:\Python\3\lib\site-packages\win32com\client\__init__.py", line 260, in
 DispatchWithEvents
    clsid = disp_class.CLSID
AttributeError: 'NoneType' object has no attribute 'CLSID'

当我尝试编译使用 win32com.client :

import win32com.client

class MMEventHandler:
    pass

sdb = win32com.client.DispatchWithEvents("SongsDB.SDBApplication", MMEventHandler)

这是我的setup.py脚本:

And this is my setup.py script:

from cx_Freeze import setup, Executable


includes = []
excludes = []
packages = ['win32com', 'shlex', 'os', 'pythoncom', 'base64', 'tornado']
filename = "test.py"
setup(
    name = 'Test',
    version = '0.1',
    description = 'test',
    author = 'no',
    author_email = 'someting@my.org',
    options = {'build_exe': {
        'excludes':excludes,
        'packages':packages,
        'includes':includes
        }},
    executables = [Executable(filename, base = None, icon = None)])


推荐答案

重新发布答案,以总结一下:

Reposting as an answer, to summarise:

对于cx_Freeze 4.3.2,我进行了更改,使其仅复制名称为有效Python标识符的模块(以便可以将其导入)。但是,win32com似乎依赖于以下模块:

For cx_Freeze 4.3.2, I made a change so that it would only copy modules with names which are valid Python identifiers (so they can be imported). However, win32com appears to rely on modules such as:

win32com\gen_py\E602ED16-8EF9-4F08-B09F-6F6E8306C51Bx0x1x0.py

连字符(-)文件名使其成为无效的Python标识符,因此不会被复制。我已经打开了一个问题 cx_Freeze。同时,一种解决方法是降级为cx_Freeze 4.3.1,您可以下载 from SourceForge

The hyphens (-) in the filename make it not a valid Python identifier, so it doesn't get copied. I've opened an issue for cx_Freeze. In the meantime, a workaround is to downgrade to cx_Freeze 4.3.1, which you can download from SourceForge.

此外,我认为这些模块是在您第一次包装COM对象时生成的。因此,请确保在冻结代码之前运行代码。

Also, I think that these modules are generated when you first wrap a COM object. So make sure that you run your code before freezing it.

这篇关于python:win32com和cx_Freeze-错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆