1

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'

It doesn't even work when I try to compile a really short script which uses win32com.client:

import win32com.client

class MMEventHandler:
    pass

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

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 = '[email protected]',
    options = {'build_exe': {
        'excludes':excludes,
        'packages':packages,
        'includes':includes
        }},
    executables = [Executable(filename, base = None, icon = None)])
10
  • 1
    Is it the same error that you get from your short example script? Commented Oct 29, 2013 at 16:56
  • 1
    This message suggests that you need to include the win32com.gen_py package when you freeze it. Let me know if that helps. Commented Oct 29, 2013 at 17:13
  • 1
    I'm going to look into this - could you put the output from freezing it in a pastebin somewhere? Commented Oct 29, 2013 at 17:39
  • 1
    I think I know what's going on. I 'fixed' cx_Freeze to ignore modules which don't have a valid Python name, but it looks like win32com relies on some like that. Do you have .py files with dashes in the name in `O:\Python\3\lib\site-packages\win32com\gen_py` ? If so, try using the previous release from here and see if that works any better. Commented Oct 29, 2013 at 18:21
  • 1
    Can you post the log from freezing with cx_Freeze 4.3.1? Commented Oct 29, 2013 at 23:49

1 Answer 1

2

Reposting as an answer, to summarise:

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

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.

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Was this ever resolved? cx_Freeze is on 4.3.4 now. Would I still need to go back to 4.3.1 if having this same problem? I found I could fix the problem if I run the python script on local machine first, and then freeze, and then copy the .py file(s) with the dashes to the correct library.zip folder and re-zip it.
It got fixed, but there hasn't been a release of cx_Freeze since then. You could install cx_Freeze from the development version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.