Import SimpleITK fails

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:

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.

Thanks for reporting. It seems that SimpleITK tests in Slicer core has been failing since ITK was updated last week (2024-06-04).

@dzenanz @jcfr Could you please have a look?

What is odd is that these results are different from my local build, package and testing that I reported in my review comment. With my installed package the import of SimpleITK is successful:

However I do see the reported import error when using the Slicer factory built versions. When viewing the configure command 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.

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

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.

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?

@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.

Slicer adds this commit which adds support for customizing ITK’s namespace. Correspondingly, a few commits 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).

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

1 Like