py2exe: problem including libxml2

Brad Clements bkc at Murkworks.com
Fri Dec 5 11:23:36 EST 2003


"Rene Olsthoorn" <rol at post.com> wrote in message
news:3fcf581e$0$200$e4fe514c at news.xs4all.nl...
> Dear readers,
>
> py2exe has a problem including libxml2. Not at building time, but at
> runtime. The libxml2.dll cannot be loaded... Is there anyone that NOT has
> the problem? (and can you drop me your setup.py scipt, please).
>

Perhaps you hit the same problem I did when using libxml2 and libxslt in a
service created by p2exe.

Here are notes from my project diary (these notes are meant for my client to
reconcile my bill vs. what I did)
-----
The service builds, I can install it, but get an error when I run it:

          The instance's SvcRun() method failed
          File "win32serviceutil.pyo", line 663, in SvcRun
          File "UMXWIN32SVC.pyo", line 41, in SvcDoRun
          File "Rose\WebServer\UMXMServer.pyo", line 53, in ?
          File "Rose\WebServer\umx_handler.pyo", line 16, in ?
          File "Rose\WebServer\HTTPHandler.pyo", line 95, in ?
          File "Rose\WebServer\XMLProcessor.pyo", line 34, in ?

          exceptions.ImportError: dynamic module does not define init
function (initlibxslt)

This says that the service cannot import the libxslt module for some reason.

I built a test script that py2exe runs in console mode, it also fails in the
same way.

I think libxml is using some kind of dynamic import mechanism, we need to
work around.

Aha, figured it out. example problem with libxml2.

libxml2.py is a module that imports libxml2mod.pyd which imports libxml2.dll

But, py2exe creates a default path like this:

         c:\\temp\\rose, c:\\temp\\rose\\library.zip

This means that python tries to import from the directory first, before
importing from library.zip. So, python imports libxml2.dll, not libxml2.py

My workaround is to reverse the order of the imports in the startup script:

       zipfile = sys.path[-1]
       sys.path.insert(0,zipfile)








More information about the Python-list mailing list