# how to build ITK 5.3.0 with Python bindings in Linux?

**URL:** <https://discourse.itk.org/t/how-to-build-itk-5-3-0-with-python-bindings-in-linux/6544>\
**Category:** Engineering\
**Tags:** build, itk-releases, python\
**Created:** [March 22, 2024, 10:48am UTC](https://discourse.itk.org/t/how-to-build-itk-5-3-0-with-python-bindings-in-linux/6544 "2024-03-22T10:48:56Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![edgar](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b487fb/32.png) [@edgar](https://discourse.itk.org/u/edgar)\
**Post date:** [March 22, 2024, 10:48am UTC](https://discourse.itk.org/t/how-to-build-itk-5-3-0-with-python-bindings-in-linux/6544/1 "2024-03-22T10:48:56Z")

</div>

Hello. I would like to know if someone can help me to build ITK 5.3.0 with Python bindings in Linux. The idea is to have a reproducible build, which implies that downloading the binary packages is not an option. Thank you in advance.

When I build like this:

```bash
    cd /pkg
    pkgname="${insight-toolkit}"
    torsocks git clone https://github.com/InsightSoftwareConsortium/ITK insight-toolkit
    torsocks curl -L "https://github.com/InsightSoftwareConsortium/ITK/pull/4066/commits/93bd9fe07e250bdac948ae6f2c2cc749f165f0e9.patch" -o InsightToolkit-gcc13-fix.patch    

    cd /pkg/insight-toolkit
    git checkout v5.3.0

    patch -Np1 -i ../InsightToolkit-gcc13-fix.patch
    git submodule update --init --recursive       

```

```bash
  _confopts=(
    -DCMAKE_INSTALL_PREFIX:FILEPATH=/usr
    -DCMAKE_BUILD_TYPE:STRING=Release
    -DCMAKE_CXX_FLAGS:STRING="-std=c++98"
    -DITK_LEGACY_SILENT:BOOL=ON
    -DBUILD_SHARED_LIBS:BOOL=ON

    -DITK_USE_SYSTEM_LIBRARIES:BOOL=ON
    -DITK_USE_SYSTEM_EXPAT:BOOL=ON
    -DITK_USE_SYSTEM_FFTW:BOOL=ON
    -DITK_USE_SYSTEM_GDCM:BOOL=ON
    -DITK_USE_SYSTEM_HDF5:BOOL=ON
    -DITK_USE_SYSTEM_JPEG:BOOL=ON
    -DITK_USE_SYSTEM_PNG:BOOL=ON
    -DITK_USE_SYSTEM_TIFF:BOOL=ON
    -DITK_USE_SYSTEM_ZLIB:BOOL=ON

    -DBUILD_TESTING:BOOL=OFF
    -DBUILD_EXAMPLES:BOOL=OFF

    -DModule_ITKReview:BOOL=ON
    -DModule_ITKIOMINC:BOOL=ON
    -DModule_ITKIOTransformMINC:BOOL=ON
    -DModule_SimpleITKFilters:BOOL=ON

    -G Ninja
    -B build -S "${pkgname}" -Wno-dev
  ) 
  cmake "${_confopts[@]}"
  samu -j6 -C build

```

The compilation works well.

When I add the Python flags for CMake

```bash
pkgname=insight-toolkit
_confopts=(
    -DCMAKE_INSTALL_PREFIX:FILEPATH=/usr
    -DCMAKE_BUILD_TYPE:STRING=Release
    -DCMAKE_CXX_FLAGS:STRING="-std=c++98"
    -DITK_LEGACY_SILENT:BOOL=ON
    -DBUILD_SHARED_LIBS:BOOL=ON

    -DITK_USE_SYSTEM_LIBRARIES:BOOL=ON
    -DITK_USE_SYSTEM_EXPAT:BOOL=ON
    -DITK_USE_SYSTEM_FFTW:BOOL=ON
    -DITK_USE_SYSTEM_GDCM:BOOL=ON
    -DITK_USE_SYSTEM_HDF5:BOOL=ON
    -DITK_USE_SYSTEM_JPEG:BOOL=ON
    -DITK_USE_SYSTEM_PNG:BOOL=ON
    -DITK_USE_SYSTEM_TIFF:BOOL=ON
    -DITK_USE_SYSTEM_ZLIB:BOOL=ON

    -DBUILD_TESTING:BOOL=OFF
    -DBUILD_EXAMPLES:BOOL=OFF

    -DModule_ITKReview:BOOL=ON
    -DModule_ITKIOMINC:BOOL=ON
    -DModule_ITKIOTransformMINC:BOOL=ON
    -DModule_SimpleITKFilters:BOOL=ON

    # Python
    -DITK_WRAP_PYTHON:BOOL=ON
    -DITK_USE_SYSTEM_SWIG:BOOL=ON
    -DITK_USE_SYSTEM_CASTXML:BOOL=ON

    # Python
    -DITK_WRAP_PYTHON:BOOL=ON
    -DITK_USE_SYSTEM_SWIG:BOOL=ON
    -DITK_USE_SYSTEM_CASTXML:BOOL=ON

    -G Ninja
    -B build -S "${pkgname}" -Wno-dev
  )
  cmake "${_confopts[@]}"
  samu -j6 -C build

```

I get this:

```auto
[2900/4214] Generating itkNarrowBandLevelSetImageFilterPython.cpp, ../../Generators/Python/itk/itkNarrowBandLevelSetImageFilterPython.py
samu: job failed: cd /pkg/insight-toolkit/src/build/Wrapping/Typedefs/python && /usr/bin/swig -c++ -python -O -features autodoc=2 -py3 -doxygen -Werror -w302 -w303 -w312 -w314 -w361 -w362 -w350 -w383 -w384 -w389 -w394 -w395 -w467 -w508 -w509 -o /pkg/insight-toolkit/src/build/Wrapping/Modules/ITKLevelSets/itkNarrowBandThresholdSegmentationLevelSetImageFilterPython.cpp -I/usr/share/swig/4.1.1/python -I/usr/share/swig/4.1.1 -I/pkg/insight-toolkit/src/insight-toolkit/Wrapping/Generators -I/pkg/insight-toolkit/src/build/Wrapping/Typedefs/python -I/pkg/insight-toolkit/src/build/Wrapping/Typedefs -outdir /pkg/insight-toolkit/src/build/Wrapping/Generators/Python/itk /pkg/insight-toolkit/src/build/Wrapping/Typedefs/itkNarrowBandThresholdSegmentationLevelSetImageFilter.i
Deprecated command line option: -py3. Ignored, this option is no longer supported.
/pkg/insight-toolkit/src/build/Wrapping/Typedefs/itkNarrowBandThresholdSegmentationLevelSetImageFilter.i:84: Warning 401: Nothing known about base class 'itk::NarrowBandLevelSetImageFilter< itk::Image< float >,itk::Image< float >,float,itk::Image< float > >'. Ignored.
/pkg/insight-toolkit/src/build/Wrapping/Typedefs/itkNarrowBandThresholdSegmentationLevelSetImageFilter.i:84: Warning 401: Maybe you forgot to instantiate 'itk::NarrowBandLevelSetImageFilter< itk::Image< float >,itk::Image< float >,float,itk::Image< float > >' using %template.
/pkg/insight-toolkit/src/build/Wrapping/Typedefs/itkNarrowBandThresholdSegmentationLevelSetImageFilter.i:176: Warning 401: Nothing known about base class 'itk::NarrowBandLevelSetImageFilter< itk::Image< float,3 >,itk::Image< float,3 >,float,itk::Image< float,3 > >'. Ignored.
/pkg/insight-toolkit/src/build/Wrapping/Typedefs/itkNarrowBandThresholdSegmentationLevelSetImageFilter.i:176: Warning 401: Maybe you forgot to instantiate 'itk::NarrowBandLevelSetImageFilter< itk::Image< float,3 >,itk::Image< float,3 >,float,itk::Image< float,3 > >' using %template.
Deprecated command line option: -py3. Ignored, this option is no longer supported.
Deprecated command line option: -py3. Ignored, this option is no longer supported.
Deprecated command line option: -py3. Ignored, this option is no longer supported.
Deprecated command line option: -py3. Ignored, this option is no longer supported.
Deprecated command line option: -py3. Ignored, this option is no longer supported.
samu: subcommand failed

```

This process takes roughly 30 minutes with 6 cores.

I tried again with CMake (without @samu@) and could not catch the log. Since it takes some time to compile from scratch, I ran again without `cmake "${_confopts[@]}"` redirecting `stderr` to `stdout` and then to a file (which is attached):

```bash
cmake --build build 2>&1 | tee compilation.log

```

[compilation.txt](https://discourse.itk.org/uploads/short-url/AmXFeAl1eFoAls61w7znpfXMorb.txt) (129.5 KB)

samurai 1.2-2  
clang 17.0.6-1  
cmake 3.28.3-1  
gcc 13.2.1-5  
swig 4.1.1-2  
python 3.11.8-1

---

<div class="post-metadata">

**Author:** ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)\
**Post date:** [March 22, 2024, 11:32am UTC](https://discourse.itk.org/t/how-to-build-itk-5-3-0-with-python-bindings-in-linux/6544/2 "2024-03-22T11:32:25Z")

</div>

Have you tried with ITK\_USE\_SYSTEM\_SWIG=OFF and CASTXML=OFF (the default)?

---

<div class="post-metadata">

**Author:** ![edgar](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b487fb/32.png) [@edgar](https://discourse.itk.org/u/edgar)\
**Post date:** [March 22, 2024, 12:11pm UTC](https://discourse.itk.org/t/how-to-build-itk-5-3-0-with-python-bindings-in-linux/6544/3 "2024-03-22T12:11:25Z")

</div>

Thank you! (for your quick answer). It wants to download sources, but there is no connection (see partial\_log.txt below)

[partial\_log.txt](https://discourse.itk.org/uploads/short-url/j9vn688401ucq8RniWetFNPl3S1.txt) (6.2 KB)

I could get the files and put them there locally, but how would I indicate the path to each file? Thanks again.

my system has:  
castxml 0.6.4  
swig 4.1.1

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [March 22, 2024, 12:39pm UTC](https://discourse.itk.org/t/how-to-build-itk-5-3-0-with-python-bindings-in-linux/6544/4 "2024-03-22T12:39:54Z")

</div>

`-DCMAKE_CXX_FLAGS:STRING="-std=c++98"` might be getting ignored, as I don’t think ITK compiles with C++ standard that old. I think that already ITK 5.0 required C++11, and that 5.3 requires C++14. 5.4 requires C++17. This is probably not the reason, but changing or removing it might be worth trying.

---

<div class="post-metadata">

**Author:** ![edgar](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b487fb/32.png) [@edgar](https://discourse.itk.org/u/edgar)\
**Post date:** [March 22, 2024, 1:40pm UTC](https://discourse.itk.org/t/how-to-build-itk-5-3-0-with-python-bindings-in-linux/6544/5 "2024-03-22T13:40:21Z")

</div>

Thank you, dzenanz. Unfortunately, the compilation fails also like that  
[partial\_log.txt](https://discourse.itk.org/uploads/short-url/gGmOnLOgTHWmmn9ijHHKSzuxHhn.txt) (120.5 KB)

---

<div class="post-metadata">

**Author:** ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)\
**Post date:** [March 22, 2024, 2:01pm UTC](https://discourse.itk.org/t/how-to-build-itk-5-3-0-with-python-bindings-in-linux/6544/6 "2024-03-22T14:01:23Z")

</div>

ITK v5.3 used swig 4.0.2 and CastXML 0.4.8, try to install those in your system if you don’t want ITK to download their own.

---

<div class="post-metadata">

**Author:** ![edgar](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b487fb/32.png) [@edgar](https://discourse.itk.org/u/edgar)\
**Post date:** [March 25, 2024, 9:29am UTC](https://discourse.itk.org/t/how-to-build-itk-5-3-0-with-python-bindings-in-linux/6544/7 "2024-03-25T09:29:52Z")

</div>

Thanks. I will try in a couple of weeks.

---

<div class="post-metadata">

**Author:** ![edgar](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b487fb/32.png) [@edgar](https://discourse.itk.org/u/edgar)\
**Post date:** [April 8, 2024, 2:39pm UTC](https://discourse.itk.org/t/how-to-build-itk-5-3-0-with-python-bindings-in-linux/6544/8 "2024-04-08T14:39:54Z")

</div>

Hi. Now running clang14 14.0.6, llvm14 14.0.6, llvm14-libs 14.0.6, swig 4.0.2 & castxml 0.4.8-1, I’m getting many of these:

```auto
In file included from /pkg/insight-toolkit/src/build/Wrapping/castxml_inputs/itkTemporalRegion.cxx:1:
In file included from /pkg/insight-toolkit/src/insight-toolkit/Modules/Core/Common/include/itkCommand.h:21:
In file included from /pkg/insight-toolkit/src/insight-toolkit/Modules/Core/Common/include/itkObject.h:31:
In file included from /pkg/insight-toolkit/src/insight-toolkit/Modules/Core/Common/include/itkLightObject.h:21:
In file included from /pkg/insight-toolkit/src/insight-toolkit/Modules/Core/Common/include/itkMacro.h:47:
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/string:42:
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/char_traits.h:42:
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/postypes.h:40:
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/cwchar:44:
/usr/include/wchar.h:422:8: error: unknown type name '_Float32'
extern _Float32 wcstof32 (const wchar_t * __restrict__ nptr,
       ^

```

---

<div class="post-metadata">

**Author:** ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)\
**Post date:** [April 8, 2024, 3:21pm UTC](https://discourse.itk.org/t/how-to-build-itk-5-3-0-with-python-bindings-in-linux/6544/9 "2024-04-08T15:21:46Z")

</div>

If you are using clang, it looks odd that you are seeing headers from gcc.

You should use the same compiler for all your dependencies. Check that you compiled swig and castxml with clang.

---

<div class="post-metadata">

**Author:** ![edgar](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b487fb/32.png) [@edgar](https://discourse.itk.org/u/edgar)\
**Post date:** [April 8, 2024, 5:51pm UTC](https://discourse.itk.org/t/how-to-build-itk-5-3-0-with-python-bindings-in-linux/6544/10 "2024-04-08T17:51:18Z")

</div>

short: compile both CastXML and ITK with Clang 14.

I wonder if there is a way to compile CastXML without Clang, but using commit `21bfa84` from the AUR recipe [https://aur.archlinux.org/castxml.git](https://aur.archlinux.org/castxml.git), with these parameters (and the aforementioned packages from Arch):

```bash
  CONFOPTS=(
    -DCMAKE_C_COMPILER=/usr/lib/llvm14/bin/clang
    -DCMAKE_CXX_COMPILER=/usr/lib/llvm14/bin/clang++
    -DCLANG_LINK_CLANG_DYLIB=1
    -DCLANG_RESOURCE_DIR=/usr/lib/llvm14/lib/clang/14.0.6/
    -DLLVM_DIR=/usr/lib/llvm14/lib/cmake/llvm/
    -DSPHINX_EXECUTABLE=/usr/bin/sphinx-build
    -DSPHINX_HTML=1
    -DSPHINX_MAN=1
    -DCMAKE_INSTALL_PREFIX=/usr
    -DCastXML_INSTALL_DOC_DIR=share/doc/castxml
    -DCastXML_INSTALL_MAN_DIR=share/man
  )
  cmake . ${CONFOPTS[@]}

```

Allowed me to build ITK 5.3.0 with Clang with these instructions

```bash
  _confopts=(
    -DCMAKE_C_COMPILER:FILEPATH=/usr/lib/llvm14/bin/clang
    -DCMAKE_CXX_COMPILER:FILEPATH=/usr/lib/llvm14/bin/clang++
    -DCMAKE_INSTALL_PREFIX:FILEPATH=/usr
    -DCMAKE_BUILD_TYPE:STRING=Release
    -DCMAKE_CXX_FLAGS:STRING="-std=c++14"
    -DITK_LEGACY_SILENT:BOOL=ON
    -DBUILD_SHARED_LIBS:BOOL=ON

    -DITK_USE_SYSTEM_LIBRARIES:BOOL=ON
    -DITK_USE_SYSTEM_EXPAT:BOOL=ON
    -DITK_USE_SYSTEM_FFTW:BOOL=ON
    -DITK_USE_SYSTEM_GDCM:BOOL=ON
    -DITK_USE_SYSTEM_HDF5:BOOL=ON
    -DITK_USE_SYSTEM_JPEG:BOOL=ON
    -DITK_USE_SYSTEM_PNG:BOOL=ON
    -DITK_USE_SYSTEM_TIFF:BOOL=ON
    -DITK_USE_SYSTEM_ZLIB:BOOL=ON

    -DBUILD_TESTING:BOOL=OFF
    -DBUILD_EXAMPLES:BOOL=OFF

    -DModule_ITKReview:BOOL=ON
    -DModule_ITKIOMINC:BOOL=ON
    -DModule_ITKIOTransformMINC:BOOL=ON

    # Python
    -DITK_WRAP_PYTHON:BOOL=ON
    -DITK_USE_SYSTEM_SWIG:BOOL=ON
    -DITK_USE_SYSTEM_CASTXML:BOOL=ON

    -B build -S "${pkgname}" -Wno-dev
  )
cmake "${_confopts[@]}"
cmake --build build

```

(roughly 1 hour and 10 minutes). Whether it works is a different question. Thanks a lot!
