[python-win32] AttributeError: 'NoneType' object has no attribute 'CLSID' from a DispatchWithEvents call

Mark Hammond mhammond at skippinet.com.au
Wed Jan 25 01:05:55 CET 2006


> I have now created the basics of my application that uses a USB HID card
> reader peripheral via a vendor supplied OCX com control, and it runs
> fine from both the IDE (WingIDE) and the command line.  Gathers the data
> and stores it cleanly.  Much happiness there. :)
>
> However, when I compile it with py2exe (in preparation for inclusion in
> an installer) - I get the following error when I  run the executable
> version that is output:
>
> #################### Trace back from .EXE version of my app [start]
> Traceback (most recent call last):
>   File "App.py", line 47, in ?
>   File "App.py", line 43, in main
>   File "wx\_core.pyo", line 7473, in __init__
>   File "wx\_core.pyo", line 7125, in _BootstrapApp
>   File "App.py", line 37, in OnInit
>   File "frmCard.pyo", line 32, in create
>   File "frmCard.pyo", line 148, in __init__
>   File "win32com\client\__init__.pyo", line 258, in DispatchWithEvents
> AttributeError: 'NoneType' object has no attribute 'CLSID'
> #################### Trace back from .EXE version of my app [end]

I think you are finding that the "gencache" stuff (ie, stuff that
automatically calls makepy) won't work quite the same in py2exe.

The good news is that py2exe does have support for this though!  In your
setup.py, change the py2exe options.  An example from the spambayes project:

py2exe_options = dict(
    packages = "spambayes.resources,encodings,spambayes.languages," \
               "spambayes.languages.es,spambayes.languages.es_AR," \
               "spambayes.languages.fr,spambayes.languages.es.DIALOGS," \
               "spambayes.languages.es_AR.DIALOGS," \
               "spambayes.languages.fr.DIALOGS",
    excludes = "win32ui,pywin,pywin.debugger", # pywin is a package, and
still seems to be included.
    includes = "dialogs.resources.dialogs,weakref", # Outlook dynamic
dialogs
    dll_excludes = "dapi.dll,mapi32.dll",
    typelibs = [
        ('{00062FFF-0000-0000-C000-000000000046}', 0, 9, 0),
        ('{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}', 0, 2, 1),
        ('{AC0714F2-3D04-11D1-AE7D-00A0C90F26F4}', 0, 1, 0),
    ]
)

Change the typelibs to the typelib of your control (and possibly any other
controls used).  Easiest way to determine this is to delete your
win32com\gen_py dir, then rerun your app from the command line, then check
what files were generated in that directory.

py2exe will then generate these typelibs at build time, and include them in
the packaged archive.  DispatchWithEvents will then correctly manage to
import these modules without attempting any generation.

Mark



More information about the Python-win32 mailing list