[Insight-users] WrapITK and py2exe/bbfreeze : how to include WrapITK in .EXE ?
Julien Lamy
lamy at unistra.fr
Tue Oct 20 12:23:49 EDT 2009
Gaëtan Lehmann a écrit :
>
> Hi Julien,
>
> Le 19 oct. 09 à 16:55, Julien Lamy a écrit :
>
>> Hi list,
>> I've been trying to build a Windows executable which includes WrapITK
>> 0.3.0 using py2exe. I've been however unable to achieve this, and keep
>> getting errors like :
>> AttributeError: 'LazyITKModule' object has no attribute 'Image'
>>
>> My "application" consists only of "import itk ; print itk.Image". I
>> have tried playing with different includes in the setup.py ("itk",
>> "InsightToolkit", "Base", ...), but was unsuccessful.
>
> Disabling lazy loading may help.
It didn't, but that put me on the way : itkBase.py uses os.listdir and
imp.find_module to process the configuration files and load the SWIG
modules. These two functions don't play nice with ZIP archives, and the
corresponding code has to be modified (cf. attached patch), as I did in
itkExtras/__init__.py (cf. first post of the thread).
I patched itkBase.py in three places :
* in LibraryLoader.load (line 195) : use zipimporter.load_module if
necessary
* when creating dirs (line 213): include search path if we're in a
frozen exe
* when creating the module_data (line 216) : use zipimporter.get_data
and exec instead of execfile
The setup.py (cf. attached file) for py2exe also had to be modified :
* the swig modules have to be explicitely included. sys.path may need
to be modified for this.
* in order to match the third patch chunk described above, the
configuration files (XXConfig.py) have to be included in the archive
The application itself can run unmodified (cf. attached hello.py) : lazy
loading is still present, and my quick test didn't show any different
behavior between the .py and the .exe version.
This is evidently not the cleanest recipe (especially the config file
part), so anybody is free to improve it and send better patches to Gaëtan :)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hello.py
Type: text/x-python
Size: 198 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091020/49febb5c/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: setup.py
Type: text/x-python
Size: 823 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091020/49febb5c/attachment-0001.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wrapitk.patch
Type: text/x-patch
Size: 2069 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091020/49febb5c/attachment.bin>
More information about the Insight-users
mailing list