# Addressing issue with "pip install itk"

**URL:** <https://discourse.slicer.org/t/addressing-issue-with-pip-install-itk/21763>\
**Category:** Development\
**Tags:** python, itk-python\
**Created:** [February 2, 2022, 4:46pm UTC](https://discourse.slicer.org/t/addressing-issue-with-pip-install-itk/21763 "2022-02-02T16:46:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebrahim](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ebrahim/32/13403_2.png) [@ebrahim](https://discourse.slicer.org/u/ebrahim)\
**Post date:** [February 2, 2022, 4:46pm UTC](https://discourse.slicer.org/t/addressing-issue-with-pip-install-itk/21763/1 "2022-02-02T16:46:39Z")

</div>

I was also playing with pip installing itk, but this [doesn’t seem to work at the moment.](https://github.com/KitwareMedical/lungair-desktop-application/issues/6#issuecomment-1025792437)

@jcfr was looking into this. It may have to do with the pip-installed ITK and the compiled ITK libraries working with the same shared memory, each under the assumption that it is their memory to manage. I don’t know, but when I backtrace the crash it seems to happen while ITK is trying to free some memory.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [February 2, 2022, 7:25pm UTC](https://discourse.slicer.org/t/addressing-issue-with-pip-install-itk/21763/2 "2022-02-02T19:25:50Z")

</div>

Analyzing the backtrace seems to indicate that the pip installed ITK libraries are attempting to register the ITK IO factories already loaded in Slicer through the built-in ITK:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/8/2881ae0c670eff87b156fa607b3bbad30c248899.png)

After talking with @thewtex , we identified a path forward and will follow up.

In a nutshell, we are evaluating approaches like these:

- delegating the loading and registration of ITK IO to python  
or
- configure the registration code in the C++ build so that the static variable uniquely identify a given build

---

<div class="post-metadata">

**Author:** ![thewtex](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/thewtex/32/32_2.png) [@thewtex](https://discourse.slicer.org/u/thewtex)\
**Post date:** [February 3, 2022, 4:54pm UTC](https://discourse.slicer.org/t/addressing-issue-with-pip-install-itk/21763/3 "2022-02-03T16:54:40Z")

</div>

Patch is here:

> <https://github.com/InsightSoftwareConsortium/ITK/pull/3156>
>
> Load IO and FFT factories at runtime based on the itk-module.cmake
> FACTORY\_NAME…S metadata, as is done with C++ static binary
> initialization.
> 
> This enables run-time discovery of all Python IO or FFT implementations.
> Some may be added with remote module Python packages.
> 
> This also addresses Slicer's use case where Slice is performing
> initialization of IO factories with static initialization. Only
> one static binary initialization is intended to be supported per
> application. Do not perform static binary initialization in the Python
> modules.
> 
> FFTImageFilter consolidation was finalized, and the required
> corresponding VnlFFTImageFilterFactory and FFTWFFTImageFilterFactory
> classes created and wrapped.
> 
> Add the missing required TransformIO wrapping.
