py2exe: problem including libxml2

R

Rene Olsthoorn

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).

Thanks in advance,
Rene O.
 
C

Chris Liechti

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).

i have no project using that lib, so i cant tell from experience.
but did you check if the lib is copied to the dist dir?
if its not copied, you may need to use the data_files option altough the
dependecies for taht lib have to be tracked manually
or the --packages or --force-imports option may help, if you load the xml
module in advance

you should probably mention which python and py2exe version you used as
well as the module you import that does not work. the 0.5 version has a
slightly different output than the older ones.

chris
 
B

Brad Clements

Rene Olsthoorn said:
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)
 
T

Thomas Heller

Brad Clements said:
Rene Olsthoorn said:
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
 
B

Brad Clements

I used a cvs checking. py2exe/__init__.py has this:

__version__ = "0.4.0"



--
Novell DeveloperNet Sysop #5

_
Thomas Heller said:
Brad Clements said:
Rene Olsthoorn said:
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
 
R

Rene Olsthoorn

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 said:
Brad Clements said:
Rene Olsthoorn said:
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
 
R

Rene Olsthoorn

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 said:
Brad Clements said:
Rene Olsthoorn said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top