Error installing pygco python package (for graphcut) in Slicer 4.11

Hi, I am trying to install pygco package in Slicer 4.11 The package installs well in regular python 3.6, 3.7 environment. But withing Slicer 4.13 installation is failing while building the wheel file. Is there any solution?
Below is the error message inside python interactor window:

pip_install(‘pygco’)
Requirement already satisfied: pygco in c:\users\usrA147\appdata\local\na-mic\slicer 4.11.20200930\lib\python\lib\site-packages (0.0.16)
Requirement already satisfied: cython in c:\users\usrA147\appdata\local\na-mic\slicer 4.11.20200930\lib\python\lib\site-packages (from pygco) (0.29.21)
command: ‘C:\Users\usrA147\AppData\Local\NA-MIC\Slicer 4.11.20200930\bin\python-real.exe’ -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"‘C:\Users\usrA147\AppData\Local\Temp\pip-install-yyvbemew\pygco\setup.py’"’"’; file=’"’"‘C:\Users\usrA147\AppData\Local\Temp\pip-install-yyvbemew\pygco\setup.py’"’"’;f=getattr(tokenize, ‘"’"‘open’"’"’, open)(file);code=f.read().replace(’"’"’\r\n’"’"’, ‘"’"’\n’"’"’);f.close();exec(compile(code, file, ‘"’"‘exec’"’"’))’ bdist_wheel -d ‘C:\Users\usrA147\AppData\Local\Temp\pip-wheel-2mzmu_b6’
cwd: C:\Users\usrA147\AppData\Local\Temp\pip-install-yyvbemew\pygco
Complete output (16 lines):
running bdist_wheel
running build
running build_ext
cythoning gco_python.pyx to gco_python.cpp
C:\Users\usrA147\AppData\Local\NA-MIC\Slicer 4.11.20200930\lib\Python\Lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive ‘language_level’ not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\usrA147\AppData\Local\Temp\pip-install-yyvbemew\pygco\gco_python.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
building ‘pygco’ extension
creating build
creating build\temp.win-amd64-3.6
creating build\temp.win-amd64-3.6\Release
creating build\temp.win-amd64-3.6\Release\gco_src
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Igco_src “-IC:\Users\usrA147\AppData\Local\NA-MIC\Slicer 4.11.20200930\lib\Python\Lib\site-packages\numpy\core\include” “-IC:\Users\usrA147\AppData\Local\NA-MIC\Slicer 4.11.20200930\lib\Python\include” “-IC:\Users\usrA147\AppData\Local\NA-MIC\Slicer 4.11.20200930\lib\Python\include” “-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include” “-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt” /EHsc /Tpgco_python.cpp /Fobuild\temp.win-amd64-3.6\Release\gco_python.obj -fpermissive
cl : Command line warning D9002 : ignoring unknown option ‘-fpermissive’
gco_python.cpp
gco_python.cpp(4): fatal error C1083: Cannot open include file: ‘Python.h’: No such file or directory
error: command ‘C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe’ failed with exit status 2


ERROR: Failed building wheel for pygco
Running setup.py clean for pygco
Failed to build pygco
Installing collected packages: pygco
Running setup.py install for pygco: started
Running setup.py install for pygco: finished with status ‘error’
ERROR: Command errored out with exit status 1:
command: ‘C:\Users\usrA147\AppData\Local\NA-MIC\Slicer 4.11.20200930\bin\python-real.exe’ -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"‘C:\Users\usrA147\AppData\Local\Temp\pip-install-yyvbemew\pygco\setup.py’"’"’; file=’"’"‘C:\Users\usrA147\AppData\Local\Temp\pip-install-yyvbemew\pygco\setup.py’"’"’;f=getattr(tokenize, ‘"’"‘open’"’"’, open)(file);code=f.read().replace(’"’"’\r\n’"’"’, ‘"’"’\n’"’"’);f.close();exec(compile(code, file, ‘"’"‘exec’"’"’))’ install --record ‘C:\Users\usrA147\AppData\Local\Temp\pip-record-j0rrv1q1\install-record.txt’ --single-version-externally-managed --compile --install-headers ‘C:\Users\usrA147\AppData\Local\NA-MIC\Slicer 4.11.20200930\lib\Python\Include\pygco’
cwd: C:\Users\usrA147\AppData\Local\Temp\pip-install-yyvbemew\pygco
Complete output (14 lines):
running install
running build
running build_ext
skipping ‘gco_python.cpp’ Cython extension (up-to-date)
building ‘pygco’ extension
creating build
creating build\temp.win-amd64-3.6
creating build\temp.win-amd64-3.6\Release
creating build\temp.win-amd64-3.6\Release\gco_src
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Igco_src “-IC:\Users\usrA147\AppData\Local\NA-MIC\Slicer 4.11.20200930\lib\Python\Lib\site-packages\numpy\core\include” “-IC:\Users\usrA147\AppData\Local\NA-MIC\Slicer 4.11.20200930\lib\Python\include” “-IC:\Users\usrA147\AppData\Local\NA-MIC\Slicer 4.11.20200930\lib\Python\include” “-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include” “-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt” /EHsc /Tpgco_python.cpp /Fobuild\temp.win-amd64-3.6\Release\gco_python.obj -fpermissive
cl : Command line warning D9002 : ignoring unknown option ‘-fpermissive’
gco_python.cpp
gco_python.cpp(4): fatal error C1083: Cannot open include file: ‘Python.h’: No such file or directory
error: command ‘C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe’ failed with exit status 2
----------------------------------------
ERROR: Command errored out with exit status 1: ‘C:\Users\usrA147\AppData\Local\NA-MIC\Slicer 4.11.20200930\bin\python-real.exe’ -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"‘C:\Users\usrA147\AppData\Local\Temp\pip-install-yyvbemew\pygco\setup.py’"’"’; file=’"’"‘C:\Users\usrA147\AppData\Local\Temp\pip-install-yyvbemew\pygco\setup.py’"’"’;f=getattr(tokenize, ‘"’"‘open’"’"’, open)(file);code=f.read().replace(’"’"’\r\n’"’"’, ‘"’"’\n’"’"’);f.close();exec(compile(code, file, ‘"’"‘exec’"’"’))’ install --record ‘C:\Users\usrA147\AppData\Local\Temp\pip-record-j0rrv1q1\install-record.txt’ --single-version-externally-managed --compile --install-headers ‘C:\Users\usrA147\AppData\Local\NA-MIC\Slicer 4.11.20200930\lib\Python\Include\pygco’ Check the logs for full command output.
WARNING: You are using pip version 20.1.1; however, version 21.0.1 is available.
You should consider upgrading via the ‘C:\Users\usrA147\AppData\Local\NA-MIC\Slicer 4.11.20200930\bin\python-real.exe -m pip install --upgrade pip’ command.
Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\usrA147\AppData\Local\NA-MIC\Slicer 4.11.20200930\bin\Python\slicer\util.py”, line 2569, in pip_install
_executePythonModule(‘pip’, args)
File “C:\Users\usrA147\AppData\Local\NA-MIC\Slicer 4.11.20200930\bin\Python\slicer\util.py”, line 2545, in _executePythonModule
logProcessOutput(proc)
File “C:\Users\usrA147\AppData\Local\NA-MIC\Slicer 4.11.20200930\bin\Python\slicer\util.py”, line 2517, in logProcessOutput
raise CalledProcessError(retcode, proc.args, output=proc.stdout, stderr=proc.stderr)
subprocess.CalledProcessError: Command ‘[‘C:/Users/usrA147/AppData/Local/NA-MIC/Slicer 4.11.20200930/bin/…/bin\PythonSlicer.EXE’, ‘-m’, ‘pip’, ‘install’, ‘pygco’]’ returned non-zero exit status 1.

Usually we don’t deal with packages that do not provide wheels, as they tend to be low-quality, non-well-maintained software. The easiest workaround is to install anaconda and Python 3.6.7 virtual environment, let anaconda build the wheel, and Slicer will find it in the anaconda cache.

It could be interesting to check what pygco can do, but it is quite likely Slicer’s grow cut segmenter in “Grow from seeds” effect, or watershed segmenter in “Watershed” effect (provided by SegmentEditorExtraEffects extension) will do a much better job on 3D medical images than any of the general-purpose graph cut implementations where segmenting 3D medical images was just one of the many applications.

1 Like

Hi Andras,
thanks for your reply. I have two quesries:
(1) Assuming I build the wheel file in Anaconda Python 3.6.7 environment - How do I make slicer point to Anaconda cache? Or do I invoke pip_install() in Slicer and pass the wheel file location in the argument.
(2) In terms of using Slicer’s grow-cut segment (a) can you point me to any example where it is being invoked programmatically - I guess I can search in Slicer github code; (b) And does it take background seed information too or just foreground seed? Thanks

We have found out accidentally that pip cache is shared between all python installations. Therefore you don’t need to do anything special - pip in Slicer’s virtual environment will find the wheel that conda built. There is no guarantee that it works like this in all computers but it worked several times, for various packages on different computers, and it is easy to try.

There are examples of using Grow from seeds from Python scrioting, without GUI in the script repository. However, since there are so many algorithms, it usually better to explore the methods with interactive GUI first, find out which works the best, and then automate the workflow.

There are several methods that does not require any background regions or can automatically determine the background seeds, and there are methods that can take any number of foreground/background input labels.

If you tell a bit more about what would you like to segment then we can give more specific advice.