[Insight-users] WrapITK and py2exe/bbfreeze : how to include WrapITK in .EXE ?

Julien Lamy lamy at unistra.fr
Mon Oct 19 10:55:13 EDT 2009


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.

The same happens with bbfreeze.

Has anybody been able to generate a .EXE which include WrapITK using 
py2exe/bbfreeze ?

By the way, the code in itkExtras/__init__.py should be patched so that 
other modules residing in itxExtras can be found when using py2exe, to 
avoid an exception being raised on os.listdir. The following excerpt 
seems to do the trick (line 823 and following in itkExtras/__init__.py).

# now loads the other modules we may found in the same directory
import os.path, sys
thisModule = sys.modules[__name__]
directory = os.path.dirname(__file__)
if hasattr(thisModule, "__loader__") :
	zipfiles = thisModule.__loader__._files.keys()
	moduleNames = [x.split(os.sep)[-1] for x in zipfiles if 
x.startswith(__name__) ]
	moduleNames = [os.path.splitext(x)[0] for x in moduleNames]
	moduleNames = [x for x in moduleNames if x != "__init__" ]
else :
	directory = os.path.dirname(__file__)
	moduleNames = [name[:-len('.py')] for name in os.listdir(directory) if 
name.endswith('.py') and name != '__init__.py']
for name in moduleNames:
   # there should be another way - I don't like to much exec -, but the 
which one ??
   exec "from %s import *" % name
# some cleaning
del directory, os, sys, moduleNames


More information about the Insight-users mailing list