Tutorial for using pyradiomics, no module named _collections

Hi to all, is there any tutorial available for using the extension pyradiomics which covers all the steps since segmentation to the analysis? I’m having trouble obtaining the results. Thank you

I’m using the latest stable version on mac

This is the error I get

RadiomicsCLI standard error:

Traceback (most recent call last):
  File "/Applications/Slicer.app/Contents/Extensions-26813/SlicerRadiomics/lib/Slicer-4.8/cli-modules/SlicerRadiomicsCLIScript", line 6, in <module>
    from radiomics.scripts import commandline
  File "/Applications/Slicer.app/Contents/Extensions-26813/SlicerRadiomics/lib/python2.7/site-packages/radiomics/__init__.py", line 4, in <module>
    import collections  # noqa: F401
  File "/Applications/Slicer.app/Contents/lib/Python/lib/python2.7/collections.py", line 20, in <module>
    from _collections import deque, defaultdict
ImportError: No module named _collections



RadiomicsCLI completed with errors

This appears to be an issue with the installation of PyRadiomics in Slicer, it is missing the package “collections”, which is normally a built-in package. Therefore, it is not checked for its presence during installation.
Which version of Slicer do you use?
If you’re using the nightly build, it may be a good idea to also try the stable build.

As to tutorials, documentation, etc on PyRadiomics, here are some useful resources:

PyRadiomics documentation: pyradiomics.readthedocs.io
PyRadiomics source code & examples: github.com/Radiomics/PyRadiomics
SlicerRadiomics source code: github.com/Radiomics/SlicerRadiomics
Radiomics start page featuring these packages: radiomics.io

Kind regards,

Joost

1 Like

Thanks for the reply. I’m using the latest stable for Mac since in the nightly build pyradiomics is not available. Do I have to reinstall pyradiomics via python or in the extension manager?

Reinstalling the extension won’t help in this case, as it does not check for the presence of the built-in modules.
I’m not sure if it works, but you could try to pip install the package.

import pip
pip.main(['install', 'collections'])

@jcfr, do you have additional suggestions?

Regards,

Joost

Collections can be imported without problem in both Slicer 4.8.1 and nightly versions on Windows.

Could you try what happens if you start Slicer and enter import collections in the Python console?

I can reproduce this in Slicer 4.8.1. import collections works fine at the Slicer python prompt, but fails from RadiomicsCLI. From vmmap, it looks like the script wrapper ends up pulling in system libpython, and confirmed by changing the wrapper call to DYLD_PRINT_LIBRARIES=1 $python_interpreter "$0Script" $* in SlicerRadiomicsCLI:

RadiomicsCLI standard error:

dyld: loaded: /opt/worksw/Slicer-4.8.1.app/Contents/bin/python-real
dyld: loaded: /usr/lib/libpython2.7.dylib
...

Presumably there is an ABI conflict. Somebody will need to dig through the (PYTHON)PATH and figure out why (I didn’t check nightly).

1 Like

Actually, I think I see the problem. Slicer python has DYLD_LIBRARY_PATH set by the launcher:

>>> os.environ["DYLD_LIBRARY_PATH"]
'/opt/worksw/Slicer-4.8.1.app/Contents/Extensions-26813/SlicerRadiomics/bin:/opt/worksw/Slicer-4.8.1.app/Contents/Extensions-26813/SlicerRadiomics/lib/Slicer-4.8:/opt/worksw/Slicer-4.8.1.app/Contents/Extensions-26813/SlicerRadiomics/lib/Slicer-4.8/cli-modules:/opt/worksw/Slicer-4.8.1.app/Contents/Extensions-26813/SlicerRadiomics/lib/Slicer-4.8:/opt/worksw/Slicer-4.8.1.app/Contents/bin:/opt/worksw/Slicer-4.8.1.app/Contents/lib/Slicer-4.8:/opt/worksw/Slicer-4.8.1.app/Contents/lib/Slicer-4.8/cli-modules:/opt/worksw/Slicer-4.8.1.app/Contents/lib/Slicer-4.8/qt-loadable-modules:../lib/Slicer-4.8/qt-loadable-modules:/opt/worksw/Slicer-4.8.1.app/Contents/lib/TclTk/lib:/opt/worksw/Slicer-4.8.1.app/Contents/lib/Python/lib:/opt/worksw/Slicer-4.8.1.app/Contents/lib/Python/lib/python2.7/site-packages/numpy/core:/opt/worksw/Slicer-4.8.1.app/Contents/lib/Python/lib/python2.7/site-packages/numpy/lib:/opt/worksw/Slicer-4.8.1.app/Contents/lib/TclTk/lib/itcl4.0.1'

But the wrapper script subshell does not inherit this setting because of Apple SIP policy. Adding echo "DYLD: $DYLD_LIBRARY_PATH" in cli-modules/SlicerRadiomicsCLI gives an empty result (DYLD:).

1 Like

This topic is related to issue #43 on the SlicerRadiomics’ github.