Did sitkUtils.PullVolumeFromSlicer() break with Slicer 5.2?

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
    return reader.Execute()
  File "/slicer5.2.1/Slicer-5.2.1-linux-amd64/lib/Python/lib/python3.9/site-packages/SimpleITK/SimpleITK.py", line 8015, in Execute
    return _SimpleITK.ImageFileReader_Execute(self)
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?

Using Slicer 5.2.1 on Windows I do not observe an error with the following code:

import SampleData
mrhead_volume = SampleData.SampleDataLogic().downloadMRHead()

import sitkUtils as su
simpleitk_image = su.PullVolumeFromSlicer(mrhead_volume)

There were some fixes for sitkUtils functionality made by @jcfr in BUG: Update SimpleITK to fix test_sitkUtils by jcfr · Pull Request #6606 · Slicer/Slicer · GitHub which should have found any issues across platforms.

Can you confirm if the code snippet above fails for you on Ubuntu 20.04? Are you using Slicer 5.2.1 downloaded from https://download.slicer.org/ or did you build it from source on your own?

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.

SimpleITK works in Slicer with a customized version. I would be suspicious if any of your additional python packages uninstalled/installed a different version of SimpleITK.

Xref the following error which happened upon installing a python package that installed another version of SimpleITK rather than keeping the Slicer customized version.

One of our in-house dependencies specified a different version of SimpleITK, which replaced Slicer’s custom version, leading to the issue. Thank you for such prompt assistance!

1 Like

Can you provide us info with which package was changing the SimpleITK version? Was it choosing the a newer or older SimpleITK version?

This issue with updating SimpleITK is currently tracked at:

There is already discussion to switch Slicer to installing SimpleITK from SimpleITK’s published whl files rather than building from source. This was discussed at:

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:

1 Like

Yet another case of a Python package requiring a very specific SimpleITK version has come up - see Run a Python script as subprocess from Slicer - #12 by lassoan

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