# Build errors : ITK Module Python Wrapping

**URL:** https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853
**Category:** Engineering
**Tags:** python, module, cmake
**Created:** [April 19, 2018, 10:47am UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853 "2018-04-19T10:47:39Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![T4mmi](https://discourse.itk.org/user_avatar/discourse.itk.org/t4mmi/32/311_2.png) [@T4mmi](https://discourse.itk.org/u/T4mmi)
#### Post date: [April 19, 2018, 10:47am UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/1 "2018-04-19T10:47:40Z")

</div>

_Hi everyone,_

_Image processing scientist, I’m pretty used to ITK pipelines. However, I’m new to ITK development…_  
_Recently converted to Python (really nice for scripting/prototyping) I’m trying to wrap some Insight Journal contributions prior to implement my own filters._

My first try is the 3D skeleton image filter : ITKbinaryThinningImageFilter3D

- I started with cookiecutter to initiate the module template,
- populated [my own module](https://github.com/T4mmi/ITKbinaryThinningImageFilter3D) using the [Insight Journal contribution](http://hdl.handle.net/10380/3588).

After some struggle with the `*.wrap ` files, I think I managed to have something almost presentable.

> **My module wont build but I’m pretty stuck in finding the reason why …**

**appveyor log**

```auto
[18/24] Completed 'swig'
[19/24] Generating itkBinaryThinningImageFilter3DPython.cpp, C:/P/IPP/ITK-win_35-x64/lib/itkBinaryThinningImageFilter3DPython.py
[20/24] Generating BinaryThinningImageFilter3DPython.cpp, C:/P/IPP/ITK-win_35-x64/lib/BinaryThinningImageFilter3DPython.py
[21/24] Building CXX object Wrapping\Modules\BinaryThinningImageFilter3D\CMakeFiles\BinaryThinningImageFilter3DPython.dir\BinaryThinningImageFilter3DPython.cpp.obj
[22/24] Building CXX object Wrapping\Modules\BinaryThinningImageFilter3D\CMakeFiles\BinaryThinningImageFilter3DPython.dir\itkBinaryThinningImageFilter3DPython.cpp.obj
[23/24] Linking CXX shared module C:\P\IPP\ITK-win_35-x64\lib\_BinaryThinningImageFilter3DPython.pyd
FAILED: C:/P/IPP/ITK-win_35-x64/lib/_BinaryThinningImageFilter3DPython.pyd 
cmd.exe /C "cd . && C:\P\IPP\venv-35-x64\Lib\site-packages\cmake\data\bin\cmake.exe -E vs_link_dll --intdir=Wrapping\Modules\BinaryThinningImageFilter3D\CMakeFiles\BinaryThinningImageFilter3DPython.dir --manifests -- C:\PROGRA~2\MI0E91~1.0\VC\bin\X86_AM~1\link.exe /nologo @CMakeFiles/BinaryThinningImageFilter3DPython.rsp /out:C:\P\IPP\ITK-win_35-x64\lib\_BinaryThinningImageFilter3DPython.pyd /implib:C:\P\IPP\ITK-win_35-x64\lib\BinaryThinningImageFilter3DPython.lib /pdb:C:\P\IPP\ITK-win_35-x64\lib\_BinaryThinningImageFilter3DPython.pdb /dll /version:0.0 /machine:x64 /INCREMENTAL:NO && cd ."
LINK: command "C:\PROGRA~2\MI0E91~1.0\VC\bin\X86_AM~1\link.exe /nologo @CMakeFiles/BinaryThinningImageFilter3DPython.rsp /out:C:\P\IPP\ITK-win_35-x64\lib\_BinaryThinningImageFilter3DPython.pyd /implib:C:\P\IPP\ITK-win_35-x64\lib\BinaryThinningImageFilter3DPython.lib /pdb:C:\P\IPP\ITK-win_35-x64\lib\_BinaryThinningImageFilter3DPython.pdb /dll /version:0.0 /machine:x64 /INCREMENTAL:NO /MANIFEST /MANIFESTFILE:C:\P\IPP\ITK-win_35-x64\lib\_BinaryThinningImageFilter3DPython.pyd.manifest" failed (exit code 1181) with the following output:
LINK : fatal error LNK1181: cannot open input file 'BinaryThinningImageFilter3D.lib'
ninja: build stopped: subcommand failed.

```

**circleci log**

```auto
[[15/16] Linking CXX shared module ../../ITK-cp27-cp27m-manylinux1_x64/lib/_BinaryThinningImageFilter3DPython.so
FAILED: ../../ITK-cp27-cp27m-manylinux1_x64/lib/_BinaryThinningImageFilter3DPython.so 
: && /opt/rh/devtoolset-2/root/usr/bin/g++ -fPIC -Wno-array-bounds -Wno-array-bounds -Os -DNDEBUG -shared -o ../../ITK-cp27-cp27m-manylinux1_x64/lib/_BinaryThinningImageFilter3DPython.so Wrapping/Modules/BinaryThinningImageFilter3D/CMakeFiles/BinaryThinningImageFilter3DPython.dir/BinaryThinningImageFilter3DPython.cpp.o Wrapping/Modules/BinaryThinningImageFilter3D/CMakeFiles/BinaryThinningImageFilter3DPython.dir/itkBinaryThinningImageFilter3DPython.cpp.o ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkdouble-conversion-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitksys-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkvnl_algo-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkvnl-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkv3p_netlib-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitknetlib-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkvcl-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKCommon-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkNetlibSlatec-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKStatistics-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKTransform-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKLabelMap-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKMesh-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkzlib-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKMetaIO-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKSpatialObjects-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKPath-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKQuadEdgeMesh-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOImageBase-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKOptimizers-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKPolynomials-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKBiasCorrection-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKDICOMParser-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKEXPAT-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkgdcmDICT-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkgdcmMSFF-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKznz-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKniftiio-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKgiftiio-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkhdf5_cpp.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkhdf5.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOBMP-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOBioRad-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOBruker-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOCSV-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOGDCM-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOIPL-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOGE-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOGIPL-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOHDF5-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkjpeg-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOJPEG-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitktiff-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOTIFF-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOLSM-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkminc2-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOMINC-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOMRC-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOMeshBase-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOMeshBYU-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOMeshVTK-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOMesh-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOMeta-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIONIFTI-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKNrrdIO-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIONRRD-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkpng-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOPNG-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOSiemens-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOXML-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOSpatialObjects-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOStimulate-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKTransformFactory-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOTransformBase-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOTransformHDF5-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOTransformInsightLegacy-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOTransformMatlab-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOVTK-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKKLMRegionGrowing-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitklbfgs-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKOptimizersv4-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKVTK-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKVideoCore-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKVideoIO-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKWatersheds-5.0.a -lBinaryThinningImageFilter3D ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkgdcmMSFF-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkgdcmDICT-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkgdcmIOD-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkgdcmDSED-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkgdcmCommon-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkgdcmjpeg8-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkgdcmjpeg12-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkgdcmjpeg16-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkgdcmopenjp2-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkgdcmcharls-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkgdcmuuid-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOTIFF-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitktiff-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkjpeg-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkminc2-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKgiftiio-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOMeshBYU-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOMeshVTK-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOMeshBase-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKQuadEdgeMesh-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKMetaIO-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKniftiio-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKznz-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKNrrdIO-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkpng-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOIPL-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOXML-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKEXPAT-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkhdf5_cpp.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkhdf5.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkzlib-5.0.a -lrt ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOTransformBase-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKTransformFactory-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKOptimizers-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitklbfgs-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKIOImageBase-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKVideoCore-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKStatistics-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkNetlibSlatec-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKSpatialObjects-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKMesh-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKTransform-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKPath-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKCommon-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkdouble-conversion-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitksys-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libITKVNLInstantiation-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkvnl_algo-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkvnl-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkv3p_netlib-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitknetlib-5.0.a ../../ITK-cp27-cp27m-manylinux1_x64/lib/libitkvcl-5.0.a -lm -lpthread -ldl -lm && :
/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-CentOS-linux/4.8.2/ld: cannot find -lBinaryThinningImageFilter3D
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "/opt/python/cp27-cp27m/lib/python2.7/site-packages/skbuild/setuptools_wrap.py", line 409, in setup
    cmkr.make(make_args, env=env)
  File "/opt/python/cp27-cp27m/lib/python2.7/site-packages/skbuild/cmaker.py", line 417, in make
    os.path.abspath(CMAKE_BUILD_DIR)))

An error occurred while building with CMake.
  Command:
    "cmake" "--build" "." "--target" "install" "--config" "MinSizeRel" "--"
  Source directory:
    /work
  Working directory:
    /work/_skbuild/cmake-build
Please see CMake's output for more information.
+ exit 1
Exited with code 1

```

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [April 19, 2018, 1:59pm UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/2 "2018-04-19T13:59:57Z")

</div>

Welcome @T4mmi,

> [@T4mmi](#):
>
> Image processing scientist, I’m pretty used to ITK pipelines. However, I’m new to ITK development…
> 
> Recently converted to Python (really nice for scripting/prototyping) I’m trying to wrap some Insight Journal contributions prior to implement my own filters.

That is excellent!

> [@T4mmi](#):
>
> My first try is the 3D skeleton image filter : ITKbinaryThinningImageFilter3D
> 
> I started with cookiecutter to initiate the module template,  
> populated my own module using the Insight Journal contribution.

Great work 👍

> [@T4mmi](#):
>
> LINK : fatal error LNK1181: cannot open input file ‘BinaryThinningImageFilter3D.lib’

> [@T4mmi](#):
>
> /opt/rh/devtoolset-2/root/usr/libexec/gcc/x86\_64-CentOS-linux/4.8.2/ld: cannot find -lBinaryThinningImageFilter3D

These errors occur because the library for the module, created in the `src` folder, was removed. We can fix the issue by removing the declaration of the libraries that the module creates here:

[https://github.com/T4mmi/ITKBinaryThinningImageFilter3D/blob/2a47008e8f65e538fa907f5e52acdffd8b55dfe4/CMakeLists.txt#L4](https://github.com/T4mmi/ITKBinaryThinningImageFilter3D/blob/2a47008e8f65e538fa907f5e52acdffd8b55dfe4/CMakeLists.txt#L4)

Hope this helps,  
Matt

---

<div class="post-metadata">

### Author: ![T4mmi](https://discourse.itk.org/user_avatar/discourse.itk.org/t4mmi/32/311_2.png) [@T4mmi](https://discourse.itk.org/u/T4mmi)
#### Post date: [April 20, 2018, 7:41am UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/3 "2018-04-20T07:41:36Z")

</div>

Oh wow thanks a lot !

**it solved the issue**

---

<div class="post-metadata">

### Author: ![T4mmi](https://discourse.itk.org/user_avatar/discourse.itk.org/t4mmi/32/311_2.png) [@T4mmi](https://discourse.itk.org/u/T4mmi)
#### Post date: [April 23, 2018, 2:51pm UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/4 "2018-04-23T14:51:23Z")

</div>

Hi again !  
First problem solved,

**BUT** [Travis CI seems broken ATM](https://github.com/travis-ci/travis-ci/issues/9531) so I might need to compile it locally for PyPI deployment. _The manual packaging of a python module `git clone http://XXX; cd XX; pip install .` might require some ‘tuned’ ITK installation that might be a turn-down for many scientists especially among python users._

No big deal, I understand that this is not a top priority question and for sure the easiest workaround would be to DL and manually compile ITK with the `ITKModuleExternal` param set to `on` in the cmake configuration.

_my question is:_

> **Is there a way to ‘force/add’ the compilation of non-essential/remote ITK modules when using a package manager (pip, conda, homebrew, chocolatey, etc …) ?**

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [April 23, 2018, 6:50pm UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/5 "2018-04-23T18:50:05Z")

</div>

Hi there,

> [@T4mmi](#):
>
> BUT Travis CI seems broken ATM so I might need to compile it locally for PyPI deployment. The manual packaging of a python module git clone [http://XXX](http://XXX); cd XX; pip install . might require some ‘tuned’ ITK installation that might be a turn-down for many scientists especially among python users.

[This change] should address the macOS Python package upload issue. We will also update the documentation to account for this change.

> [@T4mmi](#):
>
> Is there a way to ‘force/add’ the compilation of non-essential/remote ITK modules when using a package manager (pip, conda, homebrew, chocolatey, etc …) ?

It is best if users can use the pre-built binaries. What modules do you need that are not available in the default build?

---

<div class="post-metadata">

### Author: ![T4mmi](https://discourse.itk.org/user_avatar/discourse.itk.org/t4mmi/32/311_2.png) [@T4mmi](https://discourse.itk.org/u/T4mmi)
#### Post date: [April 24, 2018, 7:55am UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/6 "2018-04-24T07:55:02Z")

</div>

**Thanks a lot for you support !**

_everything seems to work,  
I still need to test the Python wrapping and see if it actually works…_

> @matt.mccormick:  
> It is best if users can use the pre-built binaries. What modules do you need that are not available in the default build?

When I try to build locally I got this error:

```auto
CMake Error at CMakeLists.txt:7 (include):
  include could not find load file:

    ITKModuleExternal

```

So I assumed it comes from the lack of the `ModuleExternal` from the pre-built distribution of PyPI but I might be wrong on this…

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [April 24, 2018, 1:54pm UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/7 "2018-04-24T13:54:14Z")

</div>

> [@T4mmi](#):
>
> everything seems to work,
> 
> I still need to test the Python wrapping and see if it actually works…

Great!

> [@T4mmi](#):
>
> When I try to build locally I got this error:
> 
> CMake Error at CMakeLists.txt:7 (include):  
> include could not find load file:
> 
> ```
> ITKModuleExternal
> 
> ```
> 
> So I assumed it comes from the lack of the ModuleExternal from the pre-built distribution of PyPI but I might be wrong on this…

Ah, correct. The binary packages on PyPI cannot be used to build additional module packages. There are some limitations on the build location, but the [ITKPythonPackage scripts](https://github.com/InsightSoftwareConsortium/ITKPythonPackage/tree/master/scripts) could be used locally, e.g. `macpython-download-cache-and-build-module-wheels.sh`. These scripts download the build trees that were used to generate the PyPI packages. But, these are not intended to be used locally, and GitHub CI generated packages are preferred.

---

<div class="post-metadata">

### Author: ![T4mmi](https://discourse.itk.org/user_avatar/discourse.itk.org/t4mmi/32/311_2.png) [@T4mmi](https://discourse.itk.org/u/T4mmi)
#### Post date: [April 24, 2018, 2:23pm UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/8 "2018-04-24T14:23:54Z")

</div>

> @matt.mccormick :  
> Ah, correct. The binary packages on PyPI cannot be used to build additional module packages. There are some limitations on the build location, but the ITKPythonPackage scripts could be used locally, e.g. macpython-download-cache-and-build-module-wheels.sh. These scripts download the build trees that were used to generate the PyPI packages. But, these are not intended to be used locally, and GitHub CI generated packages are preferred.

Ok, thats what I thought. I would not recommend using `macpython-download-cache-and-build-module-wheels.sh` outside a container as it might mess with your setup …

_Bad news, Python test of the wrapped module ends up with a nice:  
 `Bus error: 10`  
Have to look into the debugging part of the wrapping  
 🙂_

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [April 25, 2018, 7:54pm UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/9 "2018-04-25T19:54:34Z")

</div>

> [@T4mmi](#):
>
> Bad news, Python test of the wrapped module ends up with a nice:
> 
> Bus error: 10
> 
> Have to look into the debugging part of the wrapping

Hmm, is this for the macOS binaries? All the binaries?

---

<div class="post-metadata">

### Author: ![T4mmi](https://discourse.itk.org/user_avatar/discourse.itk.org/t4mmi/32/311_2.png) [@T4mmi](https://discourse.itk.org/u/T4mmi)
#### Post date: [April 26, 2018, 9:03am UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/10 "2018-04-26T09:03:20Z")

</div>

Yes, it seems so,

macOS: `Bus error: 10`  
windows: runtime error `Python has stopped working`  
linux: did not tried yet

what’s bothers me is that it does not seems to be linked to the C++ code/module as it passes the CTests with success… still learning `pdb` to investigate the python module

_so far, the PyPI module can be imported, seems like the instanciation of the `BinaryThinningImageFiltrer3D` throw a seg fault… digging into SWIG atm_

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [April 26, 2018, 2:15pm UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/11 "2018-04-26T14:15:32Z")

</div>

I don’t know if it related, but these lines should be removed:

[https://github.com/T4mmi/ITKBinaryThinning3D/blob/91d7526747862631dafec65b22cffaa6d8650439/include/itkBinaryThinningImageFilter3D.hxx#L40-L41](https://github.com/T4mmi/ITKBinaryThinning3D/blob/91d7526747862631dafec65b22cffaa6d8650439/include/itkBinaryThinningImageFilter3D.hxx#L40-L41)

The output is already created by the `itk::ImageSource` base class:

[https://github.com/InsightSoftwareConsortium/ITK/blob/fe02f8a96627bad5694a9920f54fe2e91d5fd336/Modules/Core/Common/include/itkImageSource.hxx#L49-L50](https://github.com/InsightSoftwareConsortium/ITK/blob/fe02f8a96627bad5694a9920f54fe2e91d5fd336/Modules/Core/Common/include/itkImageSource.hxx#L49-L50)

and not creating it with `MakeOutput` could cause issues.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [April 27, 2018, 10:11pm UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/12 "2018-04-27T22:11:00Z")

</div>

> [@T4mmi](#):
>
> macOS: Bus error: 10
> 
> windows: runtime error Python has stopped working
> 
> linux: did not tried yet
> 
> what’s bothers me is that it does not seems to be linked to the C++ code/module as it passes the CTests with success… still learning pdb to investigate the python module
> 
> so far, the PyPI module can be imported, seems like the instanciation of the BinaryThinningImageFiltrer3D throw a seg fault… digging into SWIG atm

@T4mmi the CI builds were recently updated to use ITK 5.0, whose binaries will not be compatible with ITK 4.0 because of the transition to C++11. This is likely causing the issue.

I will follow-up in another thread with instructions on how to address this.

In the meantime, you could try running your Python packages against the ITK 5.0 Python packages by installing `itk` with the `--pre` option for pip:

```auto
python -m pip install --upgrade --pre itk

```

---

<div class="post-metadata">

### Author: ![T4mmi](https://discourse.itk.org/user_avatar/discourse.itk.org/t4mmi/32/311_2.png) [@T4mmi](https://discourse.itk.org/u/T4mmi)
#### Post date: [April 27, 2018, 10:26pm UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/13 "2018-04-27T22:26:00Z")

</div>

Great, I’ll try this as soon as I come back to the office.

Thanks a lot for your help !

---

<div class="post-metadata">

### Author: ![T4mmi](https://discourse.itk.org/user_avatar/discourse.itk.org/t4mmi/32/311_2.png) [@T4mmi](https://discourse.itk.org/u/T4mmi)
#### Post date: [May 2, 2018, 11:53am UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/14 "2018-05-02T11:53:06Z")

</div>

No luck, even with itk v5 still got the `Bus error: 10`

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [May 6, 2018, 3:01am UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/15 "2018-05-06T03:01:21Z")

</div>

> [@T4mmi](#):
>
> No luck, even with itk v5 still got the Bus error: 10

☹ That is interesting.

Build configuration for ITK v4 is [described here](https://discourse.itk.org/t/itk-external-module-github-builds-for-4-x-and-5-x/900). Do the ITKv4 packages result in the same error?

---

<div class="post-metadata">

### Author: ![T4mmi](https://discourse.itk.org/user_avatar/discourse.itk.org/t4mmi/32/311_2.png) [@T4mmi](https://discourse.itk.org/u/T4mmi)
#### Post date: [May 14, 2018, 1:55pm UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/16 "2018-05-14T13:55:47Z")

</div>

Sorry for the delay, I was out of the office last 2 weeks.

> [@matt.mccormick](#):
>
> Build configuration for ITK v4 is described here . Do the ITKv4 packages result in the same error?

Yes, that seems to fix the problem with the [ITKv4 build](https://pypi.org/project/itk-binarythinning3d/4.0.1/). I manage to create a filter object :

```auto
In [7]: itk.BinaryThinningImageFilter3D[UnsignedCharImageType, UnsignedCharImageType].New()
Out[7]: <itkBinaryThinningImageFilter3DPython.itkBinaryThinningImageFilter3DIUC3IUC3; proxy of <Swig Object of type 'itkBinaryThinningImageFilter3DIUC3IUC3 *' at 0x10848bae0> >

```

I will stick with this solution for now since `ITKv5` is still in beta,  
**Thanks a lot for your help**

---

<div class="post-metadata">

### Author: ![T4mmi](https://discourse.itk.org/user_avatar/discourse.itk.org/t4mmi/32/311_2.png) [@T4mmi](https://discourse.itk.org/u/T4mmi)
#### Post date: [May 14, 2018, 1:57pm UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/17 "2018-05-14T13:57:34Z")

</div>

I also added a simple [python test file](https://github.com/T4mmi/ITKBinaryThinning3D/blob/ITKv4/test/BinaryThinningImageFilter3DTest.py) that mimics the CTest.  
However, it ends with a `Floating point exception: 8`, something I already experienced using the `itk.AffineTransform` but never solved…  
Could it come from a difference between the `itkCtype` and the `itk.ImagePython` ?

```auto
In [5]: InputPixelType
Out[5]: <itkCType unsigned char>

In [6]: UnsignedCharImageType
Out[6]: itkImagePython.itkImageUC3

```

in

```auto
# IO buffer
imageIO = itk.ImageIOFactory.CreateImageIO(source, itk.ImageIOFactory.ReadMode)
imageIO.SetFileName(source)
imageIO.ReadImageInformation()
# Typedef
Dimension = imageIO.GetNumberOfDimensions()
InputPixelType = itk.ctype(itk.ImageIOBase.GetComponentTypeAsString(
    imageIO.GetComponentType()).replace('_', ' ')) # prevent 'unsigned_char' error
InputImageType = itk.Image[InputPixelType, Dimension]
UnsignedCharImageType = itk.Image[itk.UC, Dimension]
# Image reader
imageFileReader = itk.ImageFileReader[InputImageType].New()
imageFileReader.SetFileName(source)

```

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [May 14, 2018, 2:11pm UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/18 "2018-05-14T14:11:31Z")

</div>

> [@T4mmi](#):
>
> I also added a simple python test file that mimics the CTest.

Very nice!

> [@T4mmi](#):
>
> However, it ends with a Floating point exception: 8, something I already experienced using the itk.AffineTransform but never solved…

Interesting.

> [@T4mmi](#):
>
> # IO buffer
> 
> imageIO = itk.ImageIOFactory.CreateImageIO(source, itk.ImageIOFactory.ReadMode)  
> imageIO.SetFileName(source)  
> imageIO.ReadImageInformation()
> 
> # Typedef
> 
> Dimension = imageIO.GetNumberOfDimensions()  
> InputPixelType = itk.ctype(itk.ImageIOBase.GetComponentTypeAsString(  
> imageIO.GetComponentType()).replace(‘\_’, ’ ')) # prevent ‘unsigned\_char’ error  
> InputImageType = itk.Image[InputPixelType, Dimension]  
> UnsignedCharImageType = itk.Image[itk.UC, Dimension]
> 
> # Image reader
> 
> imageFileReader = itk.ImageFileReader[InputImageType].New()  
> imageFileReader.SetFileName(source)

This can be written much more succinctly,

```auto
image = itk.imread(source)
InputImageType = type(image)

```

Overall, the entire pipeline can be written,

```auto
input_image = itk.imread(source)
# By passing the input_image to .New(), it sets it as the filter input and picks the required filter type automatically
thinning_filter = itk.BinaryThinningImageFilter3D.New(input_image)
itk.imwrite(thinning_filter, outputFilePath)

```

---

<div class="post-metadata">

### Author: ![T4mmi](https://discourse.itk.org/user_avatar/discourse.itk.org/t4mmi/32/311_2.png) [@T4mmi](https://discourse.itk.org/u/T4mmi)
#### Post date: [May 14, 2018, 2:31pm UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/19 "2018-05-14T14:31:09Z")

</div>

> [@matt.mccormick](#):
>
> This can be written much more succinctly,
> 
> image = itk.imread(source)  
> InputImageType = type(image)

Thanks for the tip, I thought such syntax only applied to simpleITK…  
This is far easier to read 🙂

> [@matt.mccormick](#):
>
> Overall, the entire pipeline can be written,
> 
> ```auto
> input_image = itk.imread(source)
> # By passing the input_image to .New(), it sets it as the filter input and picks the required filter type automatically
> thinning_filter = itk.BinaryThinningImageFilter3D.New(input_image)
> itk.imwrite(thinning_filter, outputFilePath)
> 
> ```

I end up with a `Segmentation fault: 11` that should correspond to the previous `Floating point exception: 8`.  
I blindly trusted the CTest that passed on CI tools, but is it possible that it succeed even with a segfault ?

I will try to extract the test resulting output image to see if the C++ module performs correctly…

---

<div class="post-metadata">

### Author: ![T4mmi](https://discourse.itk.org/user_avatar/discourse.itk.org/t4mmi/32/311_2.png) [@T4mmi](https://discourse.itk.org/u/T4mmi)
#### Post date: [May 14, 2018, 3:12pm UTC](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853/20 "2018-05-14T15:12:23Z")

</div>

Ok even stranger,  
**I tried the under Windows, everything works fine !**

I’ll try to reinstall python from scratch under macOS to see if the error is not related to my own installation. I should also try under Linux…

[Next page](https://discourse.itk.org/t/build-errors-itk-module-python-wrapping/853.md?page=2)
