# Did sitkUtils.PullVolumeFromSlicer() break with Slicer 5.2?

**URL:** <https://discourse.slicer.org/t/did-sitkutils-pullvolumefromslicer-break-with-slicer-5-2/26863>\
**Category:** Development\
**Created:** [December 21, 2022, 12:36am UTC](https://discourse.slicer.org/t/did-sitkutils-pullvolumefromslicer-break-with-slicer-5-2/26863 "2022-12-21T00:36:09Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Gilman](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_gilman/32/17737_2.png) [@Alex\_Gilman](https://discourse.slicer.org/u/Alex_Gilman)\
**Post date:** [December 21, 2022, 12:36am UTC](https://discourse.slicer.org/t/did-sitkutils-pullvolumefromslicer-break-with-slicer-5-2/26863/1 "2022-12-21T00:36:10Z")

</div>

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:

```auto
  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?

---

<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:** [December 21, 2022, 1:30am UTC](https://discourse.slicer.org/t/did-sitkutils-pullvolumefromslicer-break-with-slicer-5-2/26863/2 "2022-12-21T01:30:02Z")

</div>

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

```auto
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](https://github.com/Slicer/Slicer/pull/6606) 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/](https://download.slicer.org/) or did you build it from source on your own?

---

<div class="post-metadata">

**Author:** ![Alex\_Gilman](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_gilman/32/17737_2.png) [@Alex\_Gilman](https://discourse.slicer.org/u/Alex_Gilman)\
**Post date:** [December 21, 2022, 1:42am UTC](https://discourse.slicer.org/t/did-sitkutils-pullvolumefromslicer-break-with-slicer-5-2/26863/3 "2022-12-21T01:42:32Z")

</div>

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.

---

<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:** [December 21, 2022, 1:45am UTC](https://discourse.slicer.org/t/did-sitkutils-pullvolumefromslicer-break-with-slicer-5-2/26863/4 "2022-12-21T01:45:07Z")

</div>

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.

---

<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:** [December 21, 2022, 1:48am UTC](https://discourse.slicer.org/t/did-sitkutils-pullvolumefromslicer-break-with-slicer-5-2/26863/5 "2022-12-21T01:48:54Z")

</div>

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

> [@Slicer 5.3 Preview warnings and error messages](https://discourse.slicer.org/t/slicer-5-3-preview-warnings-and-error-messages/26457/9):
>
> “Lungmask” segmentation throws: Traceback (most recent call last): File "C:/Users/rudol/Documents/MySlicerExtensions/SlicerLungCTAnalyzer/LungCTSegmenter/LungCTSegmenter.py", line 605, in runProcessing self.logic.applySegmentation() File "C:/Users/rudol/Documents/MySlicerExtensions/SlicerLungCTAnalyzer/LungCTSegmenter/LungCTSegmenter.py", line 1688, in applySegmentation inputVolumeSitk = sitkUtils.PullVolumeFromSlicer(self.inputVolume) File "C:\Users\rudol\AppData\Local\NA-MIC\Sli…

---

<div class="post-metadata">

**Author:** ![Alex\_Gilman](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_gilman/32/17737_2.png) [@Alex\_Gilman](https://discourse.slicer.org/u/Alex_Gilman)\
**Post date:** [December 21, 2022, 2:01am UTC](https://discourse.slicer.org/t/did-sitkutils-pullvolumefromslicer-break-with-slicer-5-2/26863/6 "2022-12-21T02:01:11Z")

</div>

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!

---

<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:** [December 21, 2022, 2:09am UTC](https://discourse.slicer.org/t/did-sitkutils-pullvolumefromslicer-break-with-slicer-5-2/26863/7 "2022-12-21T02:09:56Z")

</div>

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:

> <https://github.com/Slicer/Slicer/issues/6711>
>
> \## Summary
> 
> When installing a package that requires a specific SimpleITK versi…on (e.g., TotalSegmentator requires SimpleITK==2.0.2) then installation of that package may replace Slicer's SimpleITK.
> 
> The new SimpleITK package mostly works, but the ITK IO plugins that Slicer provides (e.g., for in-memory file transfer between Slicer and ITK) don't work anymore.
> 
> \## Steps to reproduce
> 
> Run \`pip\_install('TotalSegmentator')\`.
> Slicer's SimpleITK is uninstalled and SimpleITK-2.0.2 is installed.
> 
> \## Expected behavior
> 
> Slicer's SimpleITK should not be uninstalled.
> 
> \## Environment
> \- Slicer version: Slicer-5.2.1
> \- Operating system: Windows 11

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:

> [@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):
>
> Now that Slicer [PR-6564](https://github.com/Slicer/Slicer/pull/6564) adding support for building ITK with a custom namespace has been integrated, installing SimpleITK from wheels should be possible. Pros: Reduced build time by a factor x2 (and probably more on windows) Version of SimpleITK bundled in Slicer may be update-able using pip, this would allow to install a newer SimpleITK in a released Slicer distribution. Reduced build-system complexity by removing external projects Swig, PCRE and SimpleITK and introducing python-SimpleITK C…

---

<div class="post-metadata">

**Author:** ![Alex\_Gilman](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_gilman/32/17737_2.png) [@Alex\_Gilman](https://discourse.slicer.org/u/Alex_Gilman)\
**Post date:** [December 21, 2022, 2:28am UTC](https://discourse.slicer.org/t/did-sitkutils-pullvolumefromslicer-break-with-slicer-5-2/26863/8 "2022-12-21T02:28:39Z")

</div>

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.

---

<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:** [December 21, 2022, 2:50am UTC](https://discourse.slicer.org/t/did-sitkutils-pullvolumefromslicer-break-with-slicer-5-2/26863/9 "2022-12-21T02:50:46Z")

</div>

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:

> <https://github.com/lassoan/SlicerTotalSegmentator/blob/70271651d7639bba716dcbd91dcc6e209b3fcdf1/TotalSegmentator/TotalSegmentator.py#L550-L594>

---

<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:** [February 7, 2023, 2:00pm UTC](https://discourse.slicer.org/t/did-sitkutils-pullvolumefromslicer-break-with-slicer-5-2/26863/11 "2023-02-07T14:00:50Z")

</div>

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](https://discourse.slicer.org/t/run-a-python-script-as-subprocess-from-slicer/22668/12)

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