[Insight-users] ITK python wrapping: odd failure on import

Zachary Pincus zpincus at stanford.edu
Sat, 7 Feb 2004 03:52:35 -0800


Hello,

Sorry to bother you all again. Now that I've gotten the latest CVS =20
checkout of ITK and CableSWIG to compile, I've run across a problem in =20=

the python wrappers.

Specifically, importing the InsightToolkit fails wholesale. A statement =20=

in one of the wrapper scripts refers to a symbol from an ITK library, =20=

but python cannot find that symbol. Nearby statements in the wrapper =20
script which refer to symbols from the same library work fine, and =20
using nm I can easily see the symbol in question in that library!

=10Here is the error:
(Python 2.3 compiled with GCC 3.3 on Mac OS X 10.3.2)
 >>> from InsightToolkit import *

> Traceback (most recent call last):
> [... long traceback snipped. Full version appended to the end of this =20=

> message...]
>
>   File =20
> "/Volumes/Atlotl/Developer/ITK/itk-dynamic-python-bin/bin/=20
> itkCastImageFilter_2D.py", line 1276, in =20
> itkCastImageFilterF2F2_Pointer
>     def __del__(self, destroy=3D =20
> _itkCastImageFilter_2D.delete_itkCastImageFilterF2F2_Pointer):
> AttributeError: 'module' object has no attribute =20
> 'delete_itkCastImageFilterF2F2_Pointer'

However, nm can easily find this symbol in =20
bin/_ITKBasicFiltersPython.so and in =20
Wrapping/CSwig/BasicFilters/wrap_itkCastImageFilter_2DPython.o .

More strangely, the file in question (itkCastImageFilter_2D.py) defines =20=

plenty of other python functions over symbols in those object files. In =20=

particular, the class defined in the python file just before =20
itkCastImageFilterF2F2_Pointer is itkCastImageFilterD2D2_Pointer, and =20=

for THAT class, the def __del__ statement works fine.

Note the strange fact that delete_itkCastImageFilterF2F2_Pointer (which =20=

python cannot find) and delete_itkCastImageFilterD2D2_Pointer (which =20
python easily found) are practically neighbors in those object files!

Here's a chunk of nm's output on bin/_ITKBasicFiltersPython.so

> 0178b16c s =20
> _Z43_wrap_delete_itkCastImageFilterD2D2_PointerP7_objectS0_.eh
> ...
> 0178c134 s =20
> _Z43_wrap_delete_itkCastImageFilterF2F2_PointerP7_objectS0_.eh


I've got no idea how to deal with this particular bit of strangeness. =20=

Does anyone have any ideas why Python would fail to see certain symbols =20=

in object files that seem to me to be clearly there?

Thanks,
Zach Pincus

Department of Biochemistry and Program in Biomedical Informatics
Stanford University School of Medicine




Full python traceback, if it matters:

 >>> from InsightToolkit import *

Traceback (most recent call last):
      File =20
"/Volumes/Atlotl/Developer/ITK/itk-dynamic-python-bin/Wrapping/CSwig/=20
Python/InsightToolkit.py", line 1, in ?
     from itkalgorithms import *
   File =20
"/Volumes/Atlotl/Developer/ITK/itk-dynamic-python-bin/Wrapping/CSwig/=20
Python/itkalgorithms.py", line 1, in ?
     from itkbasicfilters import *
   File =20
"/Volumes/Atlotl/Developer/ITK/itk-dynamic-python-bin/Wrapping/CSwig/=20
Python/itkbasicfilters.py", line 3, in ?
     from ITKBasicFiltersPython import *
   File "ITKBasicFiltersPython.py", line 33, in ?
     from itkCastImageFilter_2D import *
   File =20
"/Volumes/Atlotl/Developer/ITK/itk-dynamic-python-bin/bin/=20
itkCastImageFilter_2D.py", line 1214, in ?
     class itkCastImageFilterF2F2_Pointer(_object):
   File =20
"/Volumes/Atlotl/Developer/ITK/itk-dynamic-python-bin/bin/=20
itkCastImageFilter_2D.py", line 1276, in itkCastImageFilterF2F2_Pointer
     def __del__(self, destroy=3D =20
_itkCastImageFilter_2D.delete_itkCastImageFilterF2F2_Pointer):
AttributeError: 'module' object has no attribute =20
'delete_itkCastImageFilterF2F2_Pointer'