[ITK-users] FW: ITK Python wrapping

Matt McCormick matt.mccormick at kitware.com
Mon Nov 23 16:22:42 EST 2015


Dear Fabio,

To debug an ITK Python script, the ITK Python wrappings do not need to
be built with a Debug CMake build type -- any Python interpreter or
IDE can be used for debugging. At a basic level, the pdb Python module
gives gdb like functionality [1]. Newer versions of Visual Studio also
have better Python integration. Or, there are many other very nice
Python IDE's out there.  My personal favorite Python development and
debugging tool is IPython [2].


For ITK 4.9, the Python development guidelines in the ITK Software
Guide were improved based on your feedback in addition to other
improvements [3].  Also, the registration examples in the source tree
were updated [4] [5] [6] along with a new Sphinx example [7].

Python wrapping also builds more quickly in ITK 4.9.

The first ITK 4.9 release candidate will be announced soon, and your
testing and feedback will be appreciated.

Thanks,
Matt


[1] https://docs.python.org/3.5/library/pdb.html

[2] http://ipython.org/

[3] http://itk.org/ITKSoftwareGuide/html/Book1/ITKSoftwareGuide-Book1ch3.html#x34-410003.7

[4] https://github.com/InsightSoftwareConsortium/ITK/blob/547729e58d25692877f29938d19b2b1a8530ca86/Examples/RegistrationITKv4/ImageRegistration3.py

[5] https://github.com/InsightSoftwareConsortium/ITK/blob/547729e58d25692877f29938d19b2b1a8530ca86/Examples/RegistrationITKv4/ImageRegistration4.py

[6] https://github.com/InsightSoftwareConsortium/ITK/blob/547729e58d25692877f29938d19b2b1a8530ca86/Examples/RegistrationITKv4/ImageRegistration5.py

[7] http://itk.org/ITKExamples/src/Registration/Common/Perform2DTranslationRegistrationWithMeanSquares/Documentation.html

On Mon, Nov 23, 2015 at 3:38 PM, D'Isidoro  Fabio <fisidoro at ethz.ch> wrote:
> Hi Matt,
>
> Since my ITK with Python wrapping build on Visual Studio 2012 worked only in RELEASE mode (while not in Debug), my projects succeed to build only in Release mode (because there is no Debug folder with all the necessary compiled libraries and pyd files). That means that I cannot Debug step by step my codes with breakpoints (that works only in Debug mode in Visual Studio), and makes it impossible programming.
>
> What's your solution?
>
> Thank you!
>
> ----------------------------------------------------------------------
> Fabio D’Isidoro
> PhD Student – Institute for Biomechanics, ETH Zürich
> HPP O 14, Schafmattstrasse 30, 8093 Zuerich, Switzerland
> Tel: +41 44 633 40 60
>
> -----Original Message-----
> From: Insight-users [mailto:insight-users-bounces at itk.org] On Behalf Of D'Isidoro Fabio
> Sent: Mittwoch, 26. August 2015 16:42
> To: Matt McCormick
> Cc: insight-users at itk.org
> Subject: Re: [ITK-users] FW: ITK Python wrapping
>
> Hi Matt,
>
> I did the build again and this time everything is working properly :)
>
> As a summary of my issue: the key factor is that building ITK with Python Wrapping on Visual Studio on DEBUG mode did not produced the required *.pyd files. So in the guide you may want to remind an unexperienced Windows user that the build should be performed on RELEADE mode. My second problem was that the build did not work the first time for one of the modules.
>
> Just to figure out how to write in python with itk: I was trying to be lucky and to run an example similar to the example ImageRegistration3.py in the Examples folder of InsightToolkit-4.8.0 (in attachment). I start the code with 'import itk'. However fixedImageReader  = itk.ImageFileReaderF2.New()' returns an error. Is this an old version and should I just write ' fixedImageReader  = itk.ImageFileReader[ImageType].New()' instead?
>
> Which guide should I look for figuring these things out?
>
> Thank you for your valuable support.
>
> -----Original Message-----
> From: Matt McCormick [mailto:matt.mccormick at kitware.com]
> Sent: Dienstag, 25. August 2015 18:38
> To: D'Isidoro Fabio
> Cc: insight-users at itk.org
> Subject: Re: FW: [ITK-users] ITK Python wrapping
>
> Hi Fabio,
>
> We are making good progress :-).
>
> The build log indicates that the build did not complete correctly:
>
>            Traceback (most recent call last):
>            File
> "C:/Users/difabio/ITK/InsightToolkit-4.8.0/Wrapping/Generators/SwigInterface/igenerator.py",
> line 923, in <module>
>              with open(options.typedef_output, "w") as f:
>          IOError: [Errno 13] Permission denied:
> 'E:/ITK/ITK_bin_Win64_Python_Wrap/Wrapping/Typedefs/itkAffineTransformSwigInterface.h'
>      1>C:\Program Files
> (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppCommon.targets(172,5):
> error MSB6006: "cmd.exe" exited with code 1.
>      1>Done Building Project
> "E:\ITK\ITK_bin_Win64_Python_Wrap\Wrapping\Modules\ITKTransform\ITKTransformPython.vcxproj"
> (Build target(s)) -- FAILED.
>
> Please make sure the directory is writable, and run the build again.
> Sometimes, for example, anti-virus software can interfere with a build, and it should be disabled on a build directory.
>
> Hope this helps,
> Matt
>
> On Tue, Aug 25, 2015 at 11:25 AM, D'Isidoro  Fabio <fisidoro at ethz.ch> wrote:
>> Hi Matt,
>>
>> Thank you. Actually I have the .dll in the bin/release.
>>
>> Shortly, I (redundantly) added then ITKbuild/bin, ITKbuild/bin/release, ITKbuild/lib, ITKbuild/lib/release to BOTH my PATH environmental variable and the WrapITK.pth. Still not working, however I have a new error (see attachment 'error').
>>
>> Therefore I went to check the ITKTransformPython module but it's not there in lib/Release where all other .lib files relative to the other modules are. I went in the directory shown in attachment 'directory' (it's in the Wrapping/Module/.. directory) and found a  log file (attachment): the build of this module failed (I check other modules and there build there did not fail). Could you please read the log? Why did just this module fail?
>>
>> Thank you again!
>>
>> -----Original Message-----
>> From: Matt McCormick [mailto:matt.mccormick at kitware.com]
>> Sent: Dienstag, 25. August 2015 16:31
>> To: D'Isidoro Fabio; insight-users at itk.org
>> Subject: Re: FW: [ITK-users] ITK Python wrapping
>>
>> Hi Fabio,
>>
>> Thanks for the updates.
>>
>> The apparent errors are not actual errors.  These result when CMake configuration runs (indicated by the preceding "--"), and CMake tests the availability of compiler features with try_compiles [1].  If an error occurs, then that feature is not used in the build.
>>
>> It is good to see that the *.pyd files are there and your Python path.
>> There should still be *.dll files whose folder needs to be added to the PATH system environmental variable.  These are usually in the "bin" instead of "lib" directory. Search for a file "ITKCommon-4.8.dll" if you built ITK 4.8.
>>
>> Hope this helps,
>> Matt
>>
>> PS. Please reply-to-all so conversations remain on the mailing lists.
>>
>> [1] http://www.cmake.org/cmake/help/v3.3/command/try_compile.html
>>
>> On Tue, Aug 25, 2015 at 3:02 AM, D'Isidoro  Fabio <fisidoro at ethz.ch> wrote:
>>> Sorry forgot the attachments
>>>
>>> -----Original Message-----
>>> From: D'Isidoro Fabio
>>> Sent: Dienstag, 25. August 2015 09:01
>>> To: 'Matt McCormick'
>>> Subject: RE: [ITK-users] ITK Python wrapping
>>>
>>> One more thing: in the guide it's written to add to the PATH the directories containing the .dll files, suggesting ITKbuild, ITKbuild/bin and ITKbuild/bin/Release.
>>>
>>> However as you can see from the attachments the suggested directory has only executables, while the .lib files (I don't have .dll files) are in the ITKbuild/lib/Release (second attachment)...
>>>
>>> Anyway I tried to add the the ITKbuild/lib/Release directory to the PATH but it did not work either.
>>>
>>>
>>> -----Original Message-----
>>> From: Matt McCormick [mailto:matt.mccormick at kitware.com]
>>> Sent: Montag, 24. August 2015 17:08
>>> To: D'Isidoro Fabio
>>> Cc: insight-users at itk.org
>>> Subject: Re: [ITK-users] ITK Python wrapping
>>>
>>> Hi Fabio,
>>>
>>>> - Well, I have a ITKPyBasePython.pyc file in the ITK lib (and the things you told me to check are allright). So the difference is that the name has no underscore _ITKPyBasePython (as reported in the error) and the extension is pyc rather than pyd (although I have read it should not make the difference). Are those things relevant? If yes, how to correct for them? Maybe the dlls were not properly compiled so the underscore is missing?
>>>
>>> Both the .pyc and the .pyd files are required.
>>>
>>>
>>>> Depending on your reply to this email, I will then try to build ITK with Python wrapping again so that I can report the compilation failures I got regarding CastXML.
>>>
>>> Great, thank you.  A Release build instead of a Debug build is recommended -- build size and runtime performance are greatly improved.  There is on going work to substantially decrease the wrapping build time in ITK Git master, but it is currently unstable.
>>> The 4.8.0 release is recommended until that is resolved.
>>>
>>>
>>>> About the symbolic link, I just read on the guide "ln -s /path/to/ITK-Wrapped/Wrapping/Generators/Python/WrapITK.pth" and went to find out what ln -s was ... but you are right, the guide says to copy the file, so I guess you don't have improve this part. Maybe just specifiy that there is no need to download Swig.
>>>
>>> Thanks for the feedback.  We will improve the wrapping process description.
>>>
>>>
>>>> Thank you, I have spent 5 long days already with no success on this issue (which seems to me a very common issue for users willing to use the Python wrapping, from my extensive google search).
>>>
>>> Yes, wrapping has been difficult in the past, but things are changing.
>>> With your help, it will improve even quicker :-).
>>>
>>>
>>> Thanks,
>>> Matt


More information about the Insight-users mailing list