py2exe: problem including libxml2

Rene Olsthoorn rol at post.com
Wed Dec 17 10:57:21 CET 2003


Brad, Thomas,

Thanks for your help.
Brad, you were right. It is a same name problem.
The sys.path trick that Brad uses is good.
If that does not work try the following:

Go to your Python 2.3 site-packages directory. Locate the file libxml2.py
and copy it to libxml2py.py In your code use: import libxml2py as libxml2
Then, the exe generated by py2exe correctly runs.
Thomas, LibXML is a very fast XML parser. It has python bindings.
http://xmlsoft.org/python.html

Greets,
Rene Olsthoorn.

"Thomas Heller" <theller at python.net> schreef in bericht
news:fzfzt4zm.fsf at python.net...
> "Brad Clements" <bkc at Murkworks.com> writes:
>
> > "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)
>
> Which version of py2exe are you using, and what is this libxml2?
>
> IIRC, in the latest version py2exe doesn't put the executable's
> directory on the path anymore, but file names like libxml2.py,
> libxml2.pyd, and libxml2.dll all at the same time have the potential to
> confuse it!
>
> Thomas






More information about the Python-list mailing list