Cannot register dll created using "py2exe --com-dll"
Giles Brown
giles_brown at hotmail.com
Wed Jul 30 04:42:31 EDT 2003
giles_brown at hotmail.com (Giles Brown) wrote in message news:<57de9986.0307290052.688e54c5 at posting.google.com>...
> 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
added
"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
dll,
so I added the necessary '--progids' (only "ADODB.Connection.2.1" as
it happens).
<aside>
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,
1)
"""
This function takes a CLSID (? I think). If I want to use this
specific
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
thing?
</aside>
Then I found that my dll when run (for registration) was trying to
generate
an '__init__.py' in the equivalent of the gen_py folder. This was
failing
because it was looking for win32com.__gen_path__ which is not set for
frozen code. To overcome this I added (something like) the following
code
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
the
dll. This exhibited itself in the "no codec search functions
registered"
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/setup_dll.py py2exe --com-dll --include
encodings,encodings.utf_8 --excludes Tkinter --progids
ADODB.Connection.2.1
Now I need to test the DLL :-)
Cheers and thanks,
Giles
More information about the Python-list
mailing list