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

Gaëtan Lehmann gaetan.lehmann at jouy.inra.fr
Mon Oct 19 14:06:43 EDT 2009


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.
Have you tried to set LazyLoading to False in itkConfig?

   import itkConfig
   itkConfig.LazyLoading = False
   import itk

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

Ok, I will apply it.

Gaëtan


-- 
Gaëtan Lehmann
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
tel: +33 1 34 65 29 66    fax: 01 34 65 29 09
http://voxel.jouy.inra.fr  http://www.itk.org
http://www.mandriva.org  http://www.bepo.fr

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 203 bytes
Desc: Ceci est une signature ?lectronique PGP
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091019/ea4c32a5/attachment.pgp>


More information about the Insight-users mailing list