[Insight-users] wrapITK+Python2.7+Visual Studio 2010

Manuel Pinheiro manuelspinheiro2 at gmail.com
Fri Aug 3 12:03:33 EDT 2012


Hello,

I am relatively new in working with ITK, VTK and Python and this question
may be a little bit silly, but I am having some troubles in wrapping the
ITK to Python. I first started using Cmake to Configure both CableSwig and
ITK for Visual Studio 10. I basically followed the tutorial in the website:

http://www.itk.org/Wiki/ITK/Tutorials

After performing all the steps I was unable to build successfully all the
projects within ITK. I have tried to build CableSwig outside and inside the
ITK as was suggested in the website:

http://www.itk.org/ITK/resources/CableSwig.html

but unsuccessfully. I finally gave up and tried to use the ITK with Python
Wrapping Installer:

http://farsight-toolkit.org/wiki/FARSIGHT_Tutorials/Just_Installing_Software

by simply installing it I have access to the “.py” files with the ITK
wrapped functions. I also added a “WrapITK.pth” to the site-packages folder
of the python release that I am using and it worked. Currently I have
something like this:

·         $Project Folder$\Python27\Lib\site-packages\ WrapITK.pth

·         $Project Folder$\InsightToolkit

Where the “InsightToolkit” was the target installation folder of the ITK
with Python Wrapping Installer.

The problem is I am capable of importing ITK to Python, whether using the
command line or any other IDE, however I think it is not assumed as a
Python package. For instance:

// Simple program for ITK image read/write in Python

#!/usr/bin/env python

import itk

from sys import argv

pixelType = itk.UC

imageType = itk.Image[pixelType, 2]

readerType = itk.ImageFileReader[imageType]

writerType = itk.ImageFileWriter[imageType]

reader = readerType.New()

writer = writerType.New()

reader.SetFileName( argv[1] )

writer.SetFileName( argv[2] )

writer.SetInput( reader.GetOutput() )

writer.Update()


http://www.vtk.org/Wiki/ITK/Release_4/Wrapping/Examples

I am capable of doing:

pixelType = itkTypes.UC

so I am capable of recognizing itkBase, itkConfig, itkLazy, itkTypes,
itkExtras, os, sys but I am unable to do the second line

imageType = itk.Image[pixelType, 2]



What I get from the Python command line is something like this:

Traceback (most recent call last): File "<pyshell#3>", line 1, in <module>
imageType = itk.Image[pixelType,2]

File "... \InsightToolkit\lib\InsightToolkit\WrapITK\Python\itkLazy.py",
line 18, in __getattribute__ itkBase.LoadModule(module, namespace)

File "...\InsightToolkit\lib\InsightToolkit\WrapITK\Python\itkBase.py",
line 24, in LoadModule swig.__dict__.update(this_module.swig.__dict__)
AttributeError: 'module' object has no attribute 'swig'



Does anyone has/had this problem? What am I doing wrong?



Best Regards and thank you very much!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120803/271fcf63/attachment.htm>


More information about the Insight-users mailing list