ITKModuleTemplate and external modules for use with python

Hi All,

Sorry if I’ve cross-posted, but I discovered the discourse site after posting to the old mailing list.

I’m revisiting making my own external ITK module (for use in Python) after an initial attempt a while back. This time I’ve managed to get much further and have managed to successfully create python wheels following the directions on https://github.com/InsightSoftwareConsortium/ITKPythonPackage/blob/master/docs/Build_ITK_Module_Python_packages.rst , I’ve created Windows wheels via AppVeyor and linux wheels with CircleCI in addition to locally built versions via the docker based method. All tests are passed successfully.

However, after installing them with pip in a fresh virtual environment in a Python 3.6 instance (Anaconda), I seem to always get a kernel crash (segmentation fault) when I try and actually use or create one of my custom filters.

To strip everything back to basics I generated a vanilla external module, using only default values with:

python -m cookiecutter gh:InsightSoftwareConsortium/ITKModuleTemplate

I then built the wheels as described and installed them into the virtual environment.

Using the following basic python script below results in a seg fault,

import itk
InputType = itk.Image[itk.F,2]
OutputType = itk.Image[itk.F,2]
test = itk.MinimalStandardRandomVariateGenerator.New()

I get the same result if I try and create any of the classes defined in ITKModuleTemplate, however I can successfully create standard itk filters.

After running the script with gdb I see that it crashes in the call as follows:

#1 0x00007fffe7405373 in PyInit__ModuleTemplatePython () from /home/tho78s/anaconda3/lib/python3.6/site-packages/itk/Configuration/…/_ModuleTemplatePython.so

I’m currently out of ideas as to where the problem lies and I seem to get the identical problem in Windows too.

Any help or pointers in to what is going wrong would be greatly appreciated!

I you want any extra info, feel free to contact me.

Regards,

Darren

1 Like

Hi Darren,

Welcome to the ITK Discourse!

Great to hear that you have your module configured and building! :clap:

Regarding the crash, we are currently in a transition between ITK 4 and ITK 5, and the Python binaries are not compatible between the versions. For more information on how to build ITK 4 compatible binaries, please see this thread:

If you still have issues, please let us know.

Thanks,
Matt

Thanks! That was the problem, I cobbled together a solution using elements of 4.13 branch of ITKBoneMorphometry from @phcerdan and got it going.

I must say it’s quite a pleasure to use all the new “dev ops” tools like CircleCI and AppVeyor, I’d never used any of these things up until a couple of days and it was very satisfying to get working builds for multiple platforms.
As an old-school HPC C++ guy it has been quite a revelation abd having used ITK/VTK for quite a number of years now I used to always dread trying to setup build environments across the range of systems I use.

Good job!

When will ITK5 be fully ready to roll with all these tools?

Darren

Excellent!

We will release an ITK 5 release candidate over the next few months. The ITK 5 pre-release builds can be installed with pip install --upgrade --pre itk.

@phcerdan made a note in the ITKModuleTemplate README on how to build for ITKv4 to help other folks avoid the same issue, in the meantime.