Cannot import SimpleITK in build-in python

I have a problem. I compiled SlicerCustomAppTemplate, installed SimpleITK in it’s build-in python, and it crashed when I run “import SimpleITK” in python script.


My environment is Ubuntu22.04. I didn’t open the Slicer_USE_SimpleITK option when compile Slicer, but install SimpleITK by pip, because I find that there are many things to install when open the Slicer_USE_SimpleITK, is it matter?

I test other version of SimpleITK and it also doesn’t work. SimpleITK can works well in my systems python 3.10.

If you want to use SimpleITK in Slicer then you need to enable Slicer_USE_SimpleITK. If you install some ABI incompatible SimpleITK binaries from PyPI then Slicer will crash.

A special mechanism was implemented for ITK-Python that allows standalone installation from wheels (Slicer’s ITK does not clash with ITK-Python’s ITK), but as far as I know, this mechanism has not been implemented in SimpleITK. If you don’t want to build SimpleITK but you want to use ITK from Python then you can use ITK-Python.

Thank you! I’m trying to compile with Slicer_USE_SimpleITK is ON, and still encountering some difficulties. Perhaps rewrite this part of code with ITK-Python is a good idear.

If you already installed SimpleITK using pip then you may need to uninstall it, as it may interfere with the one that Slicer builds. But switching to ITK-Python could be a good solution, too.

OK! It was uninstalled. I have turned to ITK-Python, and it works well with Slicer python environment now. Thank you for your help!

1 Like