Under Ubuntu 20.04, sitkUtils.PullVolumeFromSlicer() works fine in Slicer 5.0.3. In 5.2.1 and later, the call consistently raises an error:
File "/bin/slicer5.2.1/Slicer-5.2.1-linux-amd64/bin/Python/sitkUtils.py", line 36, in PullVolumeFromSlicer
sitkimage = sitk.ReadImage(myNodeFullITKAddress)
File "/bin/slicer5.2.1/Slicer-5.2.1-linux-amd64/lib/Python/lib/python3.9/site-packages/SimpleITK/extra.py", line 346, in ReadImage
File "/slicer5.2.1/Slicer-5.2.1-linux-amd64/lib/Python/lib/python3.9/site-packages/SimpleITK/SimpleITK.py", line 8015, in Execute
RuntimeError: Exception thrown in SimpleITK ImageFileReader_Execute: /tmp/SimpleITK/Code/IO/src/sitkImageReaderBase.cxx:97:
sitk::ERROR: The file "slicer:0x273bf60#vtkMRMLLabelMapVolumeNode1" does not exist.
Is this a known issue? Does it affect other platforms? Is there a workaround?
I am using the official Slicer 5.2.1 download. However, there are a number of additional packages installed into it, some of which are in-house code. Your question prompted me to try a clean download, and the problem does not reproduce. Thank you for that, I will investigate our post-installation steps to track down the cause.
An in-house package specified SimpleITK==2.1.1 as an install requirement. I believe that is older than the custom 2.2.0 version specified by Slicer. The issue you linked is precisely the one I am facing.
Setting an exact version requirement for a Python package in a complex system is a really bad idea. Dependencies can be so tangled that by setting exact version requirements for a few packages can almost guarantee a failure somewhere. Usually exact version requirement are not even necessary, but it is just because developers are cutting corners (because setting an exact known version is simpler for a developer than exploring what range of versions work).
We ran into the same issue with TotalSegmentator and SimpleITK. If you cannot fix the problem in the package that sets the exact version requirement then you can use this technique to prevent replacement of SimpleITK:
@jcfr is there a solution for this? There are a number of bad-behaving Python packages out there that require a certain SimpleITK version. Should we drop the special Slicer memory image IO to make Slicer compatible with a broader range of SimpleITK versions?