Total Segmentator on 5.2.2 "scikit-learn" distribution not found

After installing Slicer 5.2.2, Total Segmentator is no longer working. I read through the troubleshooting and uninstalled/reinstalled PyTorch and did a Force reinstall of Total Segmentator, but still can’t run it. I’m just using one of the cardiac sample datasets, so it’s small. The error is saying that the “scikit-learn” distribution is not found.

Processing started
Writing input file to C:/Users/starb/AppData/Local/Temp/Slicer/__SlicerTemp__2023-04-03_08+02+51.749/total-segmentator-input.nii
Creating segmentations with TotalSegmentator AI...
Total Segmentator arguments: ['-i', 'C:/Users/starb/AppData/Local/Temp/Slicer/__SlicerTemp__2023-04-03_08+02+51.749/total-segmentator-input.nii', '-o', 'C:/Users/starb/AppData/Local/Temp/Slicer/__SlicerTemp__2023-04-03_08+02+51.749/segmentation', '--ml', '--task', 'total']
Traceback (most recent call last):
  File "C:\Users\starb\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Scripts\TotalSegmentator", line 93, in <module>
    main()
  File "C:\Users\starb\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Scripts\TotalSegmentator", line 82, in main
    parser.add_argument('--version', action='version', version=require("TotalSegmentator")[0].version)
  File "C:\Users\starb\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Lib\site-packages\pkg_resources\__init__.py", line 956, in require
    needed = self.resolve(parse_requirements(requirements))
  File "C:\Users\starb\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Lib\site-packages\pkg_resources\__init__.py", line 815, in resolve
    dist = self._resolve_dist(
  File "C:\Users\starb\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Lib\site-packages\pkg_resources\__init__.py", line 856, in _resolve_dist
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'scikit-learn' distribution was not found and is required by batchgenerators, nnunet-customized

Hello, on which operating system are you?

I am using Windows 10.

Just tested the whole process again (Windows 11, Laptop, GTX 1060 6 GB video RAM)

  • Downloaded Slicer 3.2.2
  • Installed into a fresh directory
  • Started 3D Slicer
  • Installed the Pytorch extension
  • Restarted
  • Installed the TotalSegmentator extension
  • Restarted
  • Loaded a test dataset
  • Switched to Totalsegmentator
  • Pressed “Apply”
  • Received one error message during the following installation processes (torch etc). This is a known error that happens every time during first installation. We are working to find a solution here.
  • Restarted Slicer
  • Switched to Totalsegmentator
  • Pressed “Apply” (fast mode)
  • installation continues, then segmentation
  • Got a good segmentation result.

I went through this a few times and managed to achieve something different if I uninstalled PyTorch, restarted, and let Total Segmentator install it on the first run, restarted, ran TS again and got this:

Processing started
Writing input file to C:/Users/starb/AppData/Local/Temp/Slicer/__SlicerTemp__2023-04-03_09+56+09.275/total-segmentator-input.nii
Creating segmentations with TotalSegmentator AI...
Total Segmentator arguments: ['-i', 'C:/Users/starb/AppData/Local/Temp/Slicer/__SlicerTemp__2023-04-03_09+56+09.275/total-segmentator-input.nii', '-o', 'C:/Users/starb/AppData/Local/Temp/Slicer/__SlicerTemp__2023-04-03_09+56+09.275/segmentation', '--ml', '--task', 'total']
Traceback (most recent call last):
  File "C:\Users\starb\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Scripts\TotalSegmentator", line 93, in <module>
    main()
  File "C:\Users\starb\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Scripts\TotalSegmentator", line 82, in main
    parser.add_argument('--version', action='version', version=require("TotalSegmentator")[0].version)
  File "C:\Users\starb\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Lib\site-packages\pkg_resources\__init__.py", line 956, in require
    needed = self.resolve(parse_requirements(requirements))
  File "C:\Users\starb\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Lib\site-packages\pkg_resources\__init__.py", line 815, in resolve
    dist = self._resolve_dist(
  File "C:\Users\starb\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Lib\site-packages\pkg_resources\__init__.py", line 844, in _resolve_dist
    env = Environment(self.entries)
  File "C:\Users\starb\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Lib\site-packages\pkg_resources\__init__.py", line 1044, in __init__
    self.scan(search_path)
  File "C:\Users\starb\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Lib\site-packages\pkg_resources\__init__.py", line 1077, in scan
    self.add(dist)
  File "C:\Users\starb\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Lib\site-packages\pkg_resources\__init__.py", line 1096, in add
    dists.sort(key=operator.attrgetter('hashcmp'), reverse=True)
  File "C:\Users\starb\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Lib\site-packages\pkg_resources\__init__.py", line 2631, in hashcmp
    self.parsed_version,
  File "C:\Users\starb\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Lib\site-packages\pkg_resources\__init__.py", line 2685, in parsed_version
    raise packaging.version.InvalidVersion(f"{str(ex)} {info}") from None
pkg_resources.extern.packaging.version.InvalidVersion: Invalid version: 'rch' (package: -)

This is the PyTorch version installed by TS:

Had you freshly installed 3D Slicer before that?

Yes I uninstalled it then reinstalled it. I still have 5.2.1 installed as well–would that matter?

Not if you newly installed 5.2.2. @lassoan do you have any ideas?

It’s finally working now. I noticed each time I reinstalled 5.2.2 that my extensions were still there, so I uninstalled 5.2.1 and removed all the files that were left in the NA-MIC folder, followed your steps above and it worked.

Thanks so much for your help!

1 Like

Excellent, great job.

1 Like

Each Slicer installation is independent, so having Slicer-5.2.1 does not affect 5.2.2 at all.

Slicer-5.2.2 has the issue that it has an updated scipy (1.9.2) that scikit-image refuses to work with. I’ve pushed a fix to the TotalSegmentator extension that guides you through how to install a compatible scipy version. This is not the same scikit-learn issue that you described above but maybe they are related.

Please install Slicer-5.2.2 from scratch into a new folder, install the latest TotalSegmentator version (that is available from tomorrow - 2023-04-04 - 10am EST) and see if it starts up correctly. It will ask you to restart the application the first time you use it.

1 Like

Thanks! I’ll try today as well to see what happens.

Fresh installation: It now works as expected and described in your above post. Thank you.

1 Like

Thanks, I will try it.

I installed the Slicer 5.3.0 + TotalSegmentator Apr 24 2023 version, it still ask to restart the slicer again and again , how to solve it ?
thanks.

win10 + Slicer 3.3 + Total Segmentator 4.23 , still get the “This module requires installing scipy version <1.9.2,”

thanks.

What version number is printed if you run this command in the Python console in Slicer?

import scipy; print(scipy.__version__)

If it is 1.9.2 then try to restart the computer, because probable some files kept open on your computer (maybe another Slicer instance is running) and restarting your computer is guaranteed to close them. Right after restart, try running TotalSegmentator again. It will ask for Slicer restart and after that then scipy version should be 1.9.1. If it is still not 1.9.1 then restart your computer again (to close all open files) and run this command in a Windows command prompt to install scipy-1.9.1:

"%localappdata%\NA-MIC\Slicer 5.2.2\bin\PythonSlicer.exe" -m pip install --upgrade pip install scipy==1.9.1

Please copy the entire output of the command here.

this get help, and latter it will download the pytorch 2.0 again, this was too slow.


even dead…
I have installed the pytorch extension before the Totalsegmentator.

After long time trying, the Totalsegmentator installed.
when using the example dataset from the github code:ct_3mm.nii
the error is as follows:

Traceback (most recent call last):
File “C:\SlicerInstall\Slicer 5.3.0\bin\Python\slicer\util.py”, line 2973, in tryWithErrorDisplay
yield
File “C:/SlicerInstall/Slicer 5.3.0/slicer.org/Extensions-31730/TotalSegmentator/lib/Slicer-5.3/qt-scripted-modules/TotalSegmentator.py”, line 264, in onApplyButton
self.logic.process(self.ui.inputVolumeSelector.currentNode(), self.ui.outputSegmentationSelector.currentNode(),
File “C:/SlicerInstall/Slicer 5.3.0/slicer.org/Extensions-31730/TotalSegmentator/lib/Slicer-5.3/qt-scripted-modules/TotalSegmentator.py”, line 799, in process
self.logProcessOutput(proc)
File “C:/SlicerInstall/Slicer 5.3.0/slicer.org/Extensions-31730/TotalSegmentator/lib/Slicer-5.3/qt-scripted-modules/TotalSegmentator.py”, line 692, in logProcessOutput
raise CalledProcessError(retcode, proc.args, output=proc.stdout, stderr=proc.stderr)
subprocess.CalledProcessError: Command ‘[‘C:/SlicerInstall/Slicer 5.3.0/bin/…/bin\PythonSlicer.EXE’, ‘C:\SlicerInstall\Slicer 5.3.0\lib\Python\Scripts\TotalSegmentator’, ‘-i’, ‘C:/Users/wxxx/AppData/Local/Temp/Slicer/__SlicerTemp__2023-04-25_15+50+32.050/total-segmentator-input.nii’, ‘-o’, ‘C:/Users/wxxx/AppData/Local/Temp/Slicer/__SlicerTemp__2023-04-25_15+50+32.050/segmentation’, ‘–ml’, ‘–task’, ‘total’, ‘–fast’]’ returned non-zero exit status 1.

the same data on the Totalsegmentator online was successful.
so, what is the problem ?
thanks.

I assumed that you use the current stable version of Slicer, installed in the default location, that’s why I provided this command: "%localappdata%\NA-MIC\Slicer 5.2.2\bin\PythonSlicer.exe" -m pip install --upgrade pip install scipy==1.9.1

It seems that you use a preview release installed in a custom location, so you need to use C:\SlicerInstall\Slicer 5.3.0\bin\PythonSlicer.EXE instead.

That said, it seems that your managed to install all prerequisites, because TotalSegmentator was launched. However, I don’t see any specific error messages from TotalSegmentator, only that the final error code was nonzero. To solve the problem, we need more information. Check the module GUI and the application log and copy here all the details. Since you seem to have a very slow and unreliable network connection, the problem is quite likely an inconvenience nolete download of one of the Python packages or the TotalSegmentator model weights.