xml.dom.minidom + py2exe
Gordon McMillan
gmcm at hypernet.com
Wed Jul 18 18:39:01 EDT 2001
Martin von Loewis wrote:
> "Thomas Heller" <thomas.heller at ion-tof.com> writes:
>
>> > It looks like the XML module is using som kind of dynamic loader
>> > (like Pmw does), and these modules naturally escape py2exe.
>>
>> This is indeed the case:
>>
>> C:\sf\py2exe\tests>c:\python20\python.exe
>> Python 2.0 (#8, Apr 25 2001, 22:09:02) [MSC 32 bit (Intel)] on win32
>> Type "copyright", "credits" or "license" for more information.
>> >>> import xml
>> >>> xml
>> <module '_xmlplus' from 'c:\python20\_xmlplus\__init__.pyc'>
>
> _xmlplus is provided by PyXML, so it is only available if PyXML is
> installed. OTOH, this was not the problem for py2exe: It (correctly)
> detected that _xmlplus could not be found, this is triggered by
> xml/__init__.py's
>
> try:
> import _xmlplus
> except ImportError:
> pass
> else:
> ...
>
> Here is a clear import statement for _xmlplus, but it is no problem if
> that fails. What did cause the problem is the code
>
> default_parser_list = ["xml.sax.expatreader"]
> ...
> for parser_name in parser_list + default_parser_list:
> try:
> return _create_parser(parser_name)
> except ImportError,e:
> import sys
> ...
> def _create_parser(parser_name):
> drv_module = __import__(parser_name,{},{},['create_parser'])
> return drv_module.create_parser()
>
> in xml/sax/__init__.py. So for freezing (py2exeing?) XML applications,
> you have to give xml.sax.expatreader as a 'static' module, and
> perhaps any additional parsers you may want to use.
You have to do a lot more than that. After all, once xml/__init__.py
runs and swaps itself for _xmlplus/__init__.py, then xml.sax.expatreader
refers to _xmlplus/sax/expatreader.py.
But when you're freezing, xml.sax.expatreader refers to
xml/sax/expatreader.py. That is, because you're using an honest
"import" in xml/__init__.py, the dependency on _xmlplus/__init__.py
can be traced. But that doesn't mean that freeze realizes that
"xml" is an alias for "_xmlplus".
- Gordon
More information about the Python-list
mailing list