Facing issue while installing python package

I have been trying to install one package in slicer and I am facing the following issue

Building wheels for collected packages: spatial_correlation_sampler
Building wheel for spatial_correlation_sampler (pyproject.toml) … error
error: subprocess-exited-with-error
× Building wheel for spatial_correlation_sampler (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [19 lines of output]
running bdist_wheel
C:\Users\TestProfile\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Lib\site-packages\torch\utils\cpp_extension.py:495: UserWarning: Attempted to use ninja as the BuildExtension backend but we could not find ninja… Falling back to using the slow distutils backend.
warnings.warn(msg.format(‘we could not find ninja.’))
running build
running build_py
creating build\lib.win-amd64-cpython-39\spatial_correlation_sampler
copying Correlation_Module\spatial_correlation_sampler\spatial_correlation_sampler.py → build\lib.win-amd64-cpython-39\spatial_correlation_sampler
copying Correlation_Module\spatial_correlation_sampler_init_.py → build\lib.win-amd64-cpython-39\spatial_correlation_sampler
running build_ext
C:\Users\TestProfile\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Lib\site-packages\torch\utils\cpp_extension.py:414: UserWarning: The detected CUDA version (12.6) has a minor version mismatch with the version that was used to compile PyTorch (12.1). Most likely this shouldn’t be a problem.
warnings.warn(CUDA_MISMATCH_WARN.format(cuda_str_version, torch.version.cuda))
building ‘spatial_correlation_sampler_backend’ extension
creating build\temp.win-amd64-cpython-39\Release\Correlation_Module
“C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.42.34321\bin\HostX86\x64\cl.exe” /c /nologo /O2 /W3 /GL /DNDEBUG /MD -DUSE_CUDA “-IC:\Users\TestProfile\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Lib\site-packages\torch\include” “-IC:\Users\TestProfile\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Lib\site-packages\torch\include\torch\csrc\api\include” “-IC:\Users\TestProfile\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Lib\site-packages\torch\include\TH” “-IC:\Users\TestProfile\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Lib\site-packages\torch\include\THC” “-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\include” “-IC:\Users\TestProfile\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\include” “-IC:\Users\TestProfile\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Include” “-IC:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.42.34321\include” “-IC:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.42.34321\ATLMFC\include” “-IC:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Auxiliary\VS\include” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\um” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\shared” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\winrt” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\cppwinrt” “-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um” /EHsc /TpCorrelation_Module\correlation.cpp /Fobuild\temp.win-amd64-cpython-39\Release\Correlation_Module\correlation.obj /MD /wd4819 /wd4251 /wd4244 /wd4267 /wd4275 /wd4018 /wd4190 /wd4624 /wd4067 /wd4068 /EHsc -std=c++17 -fopenmp -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=spatial_correlation_sampler_backend -D_GLIBCXX_USE_CXX11_ABI=0 /std:c++17
cl : Command line warning D9002 : ignoring unknown option ‘-std=c++17’
cl : Command line warning D9002 : ignoring unknown option ‘-fopenmp’
correlation.cpp
C:\Users\TestProfile\AppData\Local\NA-MIC\Slicer 5.2.2\lib\Python\Lib\site-packages\torch\include\torch/csrc/python_headers.h(12): fatal error C1083: Cannot open include file: ‘Python.h’: No such file or directory
error: command ‘C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.42.34321\bin\HostX86\x64\cl.exe’ failed with exit code 2
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for spatial_correlation_sampler
Failed to build spatial_correlation_sampler
ERROR: Could not build wheels for spatial_correlation_sampler, which is required to install pyproject.toml-based projects

[notice] A new release of pip is available: 23.0 → 24.2
[notice] To update, run: python-real.exe -m pip install --upgrade pip
PS C:\Users\TestProfile\AppData\Local\NA-MIC\Slicer 5.2.2\bin> PythonSlicer.exe -m pip install python-dev
ERROR: Could not find a version that satisfies the requirement python-dev (from versions: none)
ERROR: No matching distribution found for python-dev

[notice] A new release of pip is available: 23.0 → 24.2

Does this happen on the latest stable 5.6.2? If yes, how about the latest preview?

Hi @cpinter I am using the Slicer 5.2.2 version, as one of the application/plugin developed supports only that specific version

package name : spatial_correlation_sampler

is there a solution for this

Is there a way to install python-dev as when I am looking for a solution for this issue, I am getting suggestion like this

Read the following linked post about methods of installing packages where Whl files are having to be built from source. To summarize, build the Whl in a system install of Python and use the cached Whl file to install in the Slicer Python. A Python package requiring build from source with no Whl files available from PyPI is generally an indication of a Python project with not a lot of support.

Which code is it? Slicer developers don’t support older versions of Slicer, but can help provide guidance on the latest stable and preview releases of Slicer.

Hi @jamesobutler thanks for responding, I was able to install the same package locally, now how can I do the way you mentioned

I mean the application which was developed by us in using slicer 5.2.2

For the sake of this thread and for others that might run into the problem, can you describe how you got it to install succesfully?

How can we get you to use latest Slicer stable and preview version? Slicer 5.2.2 is quite old. Are there compatibility issues with latest Slicer? Slicer developers can help with that.

I installed that package using pip

pip install spatial_correlation_sampler

before installing it I wanted to install torch

so used the below command to install the required torch and later I installed the package it got installed

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

I am trying the same thing with SlicerPython.exe , but no luck

PythonSlicer.exe -m pip install --trusted-host=pytorch.org --trusted-host=download.pytorch.org --trusted-host=files.pytorch.org torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

above is the command I used to install torch

PythonSlicer.exe -m pip install spatial_correlation_sampler

above command I used to install the package

Is there a way where we can upgrade the python version in slicer, cause in my machine I have python 3.11 and slicer 5.2.2 is having 3.9.10

Updating Slicer’s Python version is a good bit of work that has not yet been completed by the Slicer developers, but the work is tracked at:

Slicer 5.2.2 will definitely not ever be updated to support a newer python version.

Hmm got it but atleast if I could be able to install this package it would be more helpful

For this error I placed all the required header files in the python include folder , now this error is not coming but I am getting the link error

LINK : warning LNK4044: unrecognized option ‘/lgomp’; ignored
LINK : fatal error LNK1104: cannot open file ‘python39.lib’
error: command ‘C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.42.34321\bin\HostX86\x64\link.exe’ failed with exit code 1104

Can you help me with this, so that I will try this way and see whether I have a solution for the issue

Others might chime in but i think you will have to build both Slicer and this python package from source using the same build tools to avoid that problem.

I thought things worked in ubuntu, maybe focus on working on that?

Also, why are you trying with 5.2.2? Did you try with the latest stable?

I am actually consuming one of the plugin which is developed with this version of Slicer and making changes to it . Thats the main reason I using this version. Tried with latest version of slicer but the plugin is not working