Cannot register dll created using "py2exe --com-dll"

Giles Brown giles_brown at
Wed Jul 30 10:42:31 CEST 2003

giles_brown at (Giles Brown) wrote in message news:<57de9986.0307290052.688e54c5 at>...
> I'm feeling quite dumb this morning.

Next morning not quite so dumb.  Finally got the dll to register so
I thought I'd post my findings for the record.

Mark was spot on (of course!) about the lost python exception.  I
"import win32traceutil" into boot_com_server and low the traceback
showed in pythonwin.

I had omitted to mention that I am using win32com client inside the
so I added the necessary '--progids' (only "ADODB.Connection.2.1" as
it happens).

Inside one of my modules I use the gencache.EnsureModule function. 
"""#Microsoft ActiveX Data Objects 2.1 Library
# {00000201-0000-0010-8000-00AA006D2EA4}, lcid=0, major=2, minor=1
gencache.EnsureModule('{00000201-0000-0010-8000-00AA006D2EA4}', 0, 2,
This function takes a CLSID (? I think).  If I want to use this
typelib based module, how do I determine what progid to give to py2exe
to ensure that this module is picked up?  Or am I doing the wrong

Then I found that my dll when run (for registration) was trying to
an '' in the equivalent of the gen_py folder.  This was
because it was looking for win32com.__gen_path__ which is not set for 
frozen code.  To overcome this I added (something like) the following
to my module that was included the EnsureModule call.

if getattr(pythoncom, 'frozen', False):

    import os
    import win32com
    import tempfile

    # Assign (temporary) directory for gencache
    # (tempfile.tempdir is always 'None' so use TemporaryFile()) :-(
    win32com.__gen_path__ = os.path.join(os.path.dirname(
        tempfile.TemporaryFile().name), 'gencache')

Finally I was getting the "codec" problem.  I tried '--packages
encodings' but
for some reason this did not seem to build encodings.__init__.pyc into
dll.  This exhibited itself in the "no codec search functions
LookupError.  Adding '--include encodings" fixed this.  This lead (not
unreasonably) to a "unknown encoding: utf-8" LookupError which was
fixed by
added ",encodings.utf_8" to the command line.

The final working command line looked like this:
c:\python23\python madeupname/ py2exe --com-dll --include
encodings,encodings.utf_8 --excludes Tkinter --progids

Now I need to test the DLL :-)

Cheers and thanks,

More information about the Python-list mailing list