# Reduced dependencies for ITK external modules

**URL:** https://discourse.itk.org/t/reduced-dependencies-for-itk-external-modules/5391
**Category:** Engineering
**Tags:** python
**Created:** [October 6, 2022, 1:57pm UTC](https://discourse.itk.org/t/reduced-dependencies-for-itk-external-modules/5391 "2022-10-06T13:57:00Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![dyoll](https://discourse.itk.org/user_avatar/discourse.itk.org/dyoll/32/2311_2.png) [@dyoll](https://discourse.itk.org/u/dyoll)
#### Post date: [October 6, 2022, 1:57pm UTC](https://discourse.itk.org/t/reduced-dependencies-for-itk-external-modules/5391/1 "2022-10-06T13:57:00Z")

</div>

I would like to reduce dependencies to only the minimal ITK modules, instead of pulling in all of itk from pypi.

> <https://github.com/dyollb/ITKDissolve/pull/7>
>
> this MR reduces the dependency from \`itk\` to \`itk-core\`.

Since my code only depends on `ITKCommon` I tried using `itk-core` as dependency.

I did `pip install itk_dissolve-1.0.3-cp39-cp39-win_amd64.whl`:  
Then if I try to use the package I get following error:

```python
python -c "import itk; print(itk.dissolve_mask_image_filter)"

```

> Traceback (most recent call last):  
> File “”, line 1, in   
> File “C:\Users\lloyd\Downloads\WindowsWheel3.9.venv\lib\site-packages\itk\support\lazy.py”, line 132, in **getattribute**  
> base.itk\_load\_swig\_module(module, namespace)  
> File “C:\Users\lloyd\Downloads\WindowsWheel3.9.venv\lib\site-packages\itk\support\base.py”, line 102, in itk\_load\_swig\_module  
> itk\_load\_swig\_module(dep, namespace)  
> File “C:\Users\lloyd\Downloads\WindowsWheel3.9.venv\lib\site-packages\itk\support\base.py”, line 98, in itk\_load\_swig\_module  
> l\_data = itk\_base\_global\_module\_data[name]  
> KeyError: ‘ITKImageSources’

My itk-module.cmake file contains:

```cmake
itk_module(Dissolve
  DEPENDS
    ITKCommon
  COMPILE_DEPENDS
    ITKImageSources
  TEST_DEPENDS
    ITKTestKernel
    ITKMetaIO
  DESCRIPTION
    "${DOCUMENTATION}"
  EXCLUDE_FROM_DEFAULT
  ENABLE_SHARED
)

```

which also contains the `ITKImageSources` key word. What would `ITKImageSources` map to in terms of python modules? itk-filtering?

(I am not sure if the dependency to ITKImageSources is needed - maybe it is just a copy paste from another external module).

---

<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: [October 6, 2022, 2:06pm UTC](https://discourse.itk.org/t/reduced-dependencies-for-itk-external-modules/5391/2 "2022-10-06T14:06:21Z")

</div>

Yes, [ImageSources](https://github.com/InsightSoftwareConsortium/ITK/tree/master/Modules/Filtering/ImageSources) are in filtering.

A way to check correctness of these dependencies is to build ITK with ITK\_BUILD\_DEFAULT\_MODULES=OFF and ITKGroup\_Core=OFF. Then only the declared dependencies will be built.

Edit: you will need to set Module\_ITKCommon=ON and maybe Module\_ITKImageSources=ON.

---

<div class="post-metadata">

### Author: ![dyoll](https://discourse.itk.org/user_avatar/discourse.itk.org/dyoll/32/2311_2.png) [@dyoll](https://discourse.itk.org/u/dyoll)
#### Post date: [October 6, 2022, 2:29pm UTC](https://discourse.itk.org/t/reduced-dependencies-for-itk-external-modules/5391/3 "2022-10-06T14:29:04Z")

</div>

thanks @dzenanz

---

<div class="post-metadata">

### Author: ![dyoll](https://discourse.itk.org/user_avatar/discourse.itk.org/dyoll/32/2311_2.png) [@dyoll](https://discourse.itk.org/u/dyoll)
#### Post date: [October 6, 2022, 4:50pm UTC](https://discourse.itk.org/t/reduced-dependencies-for-itk-external-modules/5391/4 "2022-10-06T16:50:37Z")

</div>

@dzenanz I checked and I could set `COMPILE_DEPENDS` to `ITKCommon` and now the package works.

Out of curiosity: What is the difference between `DEPENDS` and `COMPILE_DEPENDS`?

---

<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: [October 6, 2022, 6:27pm UTC](https://discourse.itk.org/t/reduced-dependencies-for-itk-external-modules/5391/5 "2022-10-06T18:27:17Z")

</div>

Depends requires the modules for use, e.g. by publicly including it in header files. Compile depends indicates it is only required for compiling the module but not for using it. That makes sense only for modules which have a compiled part, i.e. modules which are not header-only.

---

<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: [October 6, 2022, 6:29pm UTC](https://discourse.itk.org/t/reduced-dependencies-for-itk-external-modules/5391/6 "2022-10-06T18:29:59Z")

</div>

Example where compile depends would make sense: module A is header-only, and module B’s compile part uses module A but does not expose it in its public interface. If module A had a compile part too, regular depends would be required because or requiring A’s DLL at runtime.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [October 7, 2022, 12:15pm UTC](https://discourse.itk.org/t/reduced-dependencies-for-itk-external-modules/5391/7 "2022-10-07T12:15:41Z")

</div>

> [@dyoll](#):
>
> @dzenanz I checked and I could set `COMPILE_DEPENDS` to `ITKCommon` and now the package works.
> 
> Out of curiosity: What is the difference between `DEPENDS` and `COMPILE_DEPENDS`?

Was that with static or shared libraries? If you are using ITKCommon, there is a “runtime” library dependency that is needed. Depending on the OS/compiler used the order of linking of libraries can matter. Based on @dzenanz explanation this is not a COMPILE\_DEPENDS situation, so there will likely be some problems with certain configurations and systems.

---

<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: [October 7, 2022, 12:54pm UTC](https://discourse.itk.org/t/reduced-dependencies-for-itk-external-modules/5391/8 "2022-10-07T12:54:06Z")

</div>

@dyoll I don’t think you need [set(TopologyControl\_LIBRARIES ITKCommon)](https://github.com/dyollb/ITKTopologyControl/blob/4164f11512d4a055df5867848e063e66c0fe584e/CMakeLists.txt#L4), as your module is header-only and you are not using any external libraries. Having ITKCommon in your module’s DEPENDS section implies linking to it.
