# Import SimpleITK fails

**URL:** <https://discourse.slicer.org/t/import-simpleitk-fails/36735>\
**Category:** Support\
**Created:** [June 12, 2024, 8:19pm UTC](https://discourse.slicer.org/t/import-simpleitk-fails/36735 "2024-06-12T20:19:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![smrolfe](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/smrolfe/32/3659_2.png) [@smrolfe](https://discourse.slicer.org/u/smrolfe)\
**Post date:** [June 12, 2024, 8:19pm UTC](https://discourse.slicer.org/t/import-simpleitk-fails/36735/1 "2024-06-12T20:19:03Z")

</div>

Import of SimpleITK is failing using the latest Preview version on a Windows OS. Mac OS seems to work fine. The error I’m getting is:

```auto
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Users\srolfe\AppData\Local\slicer.org\Slicer 5.7.0-2024-06-10\lib\Python\Lib\site-packages\SimpleITK\ __init__.py", line 18, in <module>
    from SimpleITK.SimpleITK import *
  File "C:\Users\srolfe\AppData\Local\slicer.org\Slicer 5.7.0-2024-06-10\lib\Python\Lib\site-packages\SimpleITK\SimpleITK.py", line 13, in <module>
    from . import _SimpleITK
ImportError: DLL load failed while importing _SimpleITK: The specified module could not be found.

```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 13, 2024, 1:38am UTC](https://discourse.slicer.org/t/import-simpleitk-fails/36735/2 "2024-06-13T01:38:35Z")

</div>

Thanks for reporting. It seems that [SimpleITK tests in Slicer core has been failing](https://slicer.cdash.org/viewTest.php?buildid=3415654&onlyfailed) since [ITK was updated last week](https://github.com/Slicer/Slicer/commit/acf3dd47940665869765584564b38439f73ff1d5) (2024-06-04).

@dzenanz @jcfr Could you please have a look?

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [June 13, 2024, 3:32am UTC](https://discourse.slicer.org/t/import-simpleitk-fails/36735/3 "2024-06-13T03:32:13Z")

</div>

What is odd is that these results are different from my local build, package and testing that I reported in my [review comment](https://github.com/Slicer/Slicer/pull/7771#pullrequestreview-2094047926). With my installed package the import of SimpleITK is successful:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/7/d7234aa4831e2155fe28fe8be6e4f95d218ffdc4.png)

However I do see the reported import error when using the Slicer factory built versions. When viewing the [configure command](https://slicer.cdash.org/builds/3424065/configure) of recent Slicer preview builds I see that it is using

- CMake 3.22.1 (released December 7th 2021)
- Visual Studio 2022 \>=17.9.6, \<17.10

My successful build was with:

- CMake 3.28.3 (released February 5th 2024)
- Visual Studio 2022 17.9.5.

I wouldn’t be surprised if the older CMake version may be having issues with this latest SimpleITK.

---

<div class="post-metadata">

**Author:** ![blowekamp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/blowekamp/32/1386_2.png) [@blowekamp](https://discourse.slicer.org/u/blowekamp)\
**Post date:** [June 13, 2024, 12:59pm UTC](https://discourse.slicer.org/t/import-simpleitk-fails/36735/4 "2024-06-13T12:59:33Z")

</div>

A recent change to the building of SimpleITK was to enable the Python Limited or Stable API:

> <https://github.com/SimpleITK/SimpleITK/pull/2121/files>
>
> More information on the Python Stable API:
> https://docs.python.org/3/c-api/stab…le.html
> 
> Requires Python 3.11+, SWIG 4.2+, and CMake 3.26+.

There is some conditional logic on the version of CMake, SWIG and Python to enable this feature. It may be a good place to start looking at the configuration output of SimpleITK and it’s Python configuration.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [June 13, 2024, 1:11pm UTC](https://discourse.slicer.org/t/import-simpleitk-fails/36735/5 "2024-06-13T13:11:58Z")

</div>

I have already spent ~10 hours on this update. It would be good if someone else hunted this down. Maybe even someone more familiar with SimpleITK than me?

---

<div class="post-metadata">

**Author:** ![blowekamp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/blowekamp/32/1386_2.png) [@blowekamp](https://discourse.slicer.org/u/blowekamp)\
**Post date:** [June 17, 2024, 3:25pm UTC](https://discourse.slicer.org/t/import-simpleitk-fails/36735/6 "2024-06-17T15:25:42Z")

</div>

@dzenanz Was the update to SimpleITK required?

I am just noticing that Slicer is using a forked version of SimpleITK. And looking into why… There is a lit for me to catch up on the help out. Let me know how I can help.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [June 17, 2024, 3:35pm UTC](https://discourse.slicer.org/t/import-simpleitk-fails/36735/7 "2024-06-17T15:35:21Z")

</div>

Slicer adds [this commit](https://github.com/Slicer/ITK/commit/aacaefd6366bb09e09faefd173d4d3797f386ad0) which adds support for customizing ITK’s namespace. Correspondingly, [a few commits](https://github.com/Slicer/SimpleITK/commits/slicer-v2.3.1-2024-05-20-bc4449e/) are added to SimpleITK. Updating ITK without also updating SimpleITK runs into errors (I did this a month ago so I don’t remember exactly what compiler complained about).

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [June 17, 2024, 3:40pm UTC](https://discourse.slicer.org/t/import-simpleitk-fails/36735/8 "2024-06-17T15:40:44Z")

</div>

Some links to refresh the memory regarding the Slicer SimpleITK fork and thoughts to reconsider using PyPI whl.

> <https://github.com/Slicer/Slicer/pull/6606#issuecomment-1286278137>
>
> \> going to be necessary in a Slicer SimpleITK fork moving forward or is there a …diff that is flexible enough for integration into the SimpleITK upstream?
> 
> I started to discuss this with @blowekamp in https://github.com/Slicer/SimpleITK/commit/ca0c09386219dfff61975437b7ea32b246adb724#r87443367
> 
> Also worth noting that building SimpleITK may not be required in the future, see https://discourse.slicer.org/t/proposal-install-simpleitk-from-wheels-instead-of-building-from-source/25635

> [@Proposal: Install SimpleITK from wheels instead of building from source](https://discourse.slicer.org/t/proposal-install-simpleitk-from-wheels-instead-of-building-from-source/25635/4):
>
> Things have observed to break down when Slicer’s SimpleITK is uninstalled a SimpleITK upstream version is installed from whl. [Slicer's embedded SimpleITK can be removed by pip · Issue #6711 · Slicer/Slicer · GitHub](https://github.com/Slicer/Slicer/issues/6711) As of right now it seems that proceeding with using SimpleITK whl files is not possible within Slicer due to requiring the fixes made in [BUG: Update SimpleITK to fix test\_sitkUtils by jcfr · Pull Request #6606 · Slicer/Slicer · GitHub](https://github.com/Slicer/Slicer/pull/6606) which are not in SimpleITK upstream.
