InsightSoftwareConsortium / ITK

Insight Toolkit (ITK) -- Official Repository. ITK builds on a proven, spatially-oriented architecture for processing, segmentation, and registration of scientific images in two, three, or more dimensions.
https://itk.org
Apache License 2.0
1.43k stars 664 forks source link

ITK Python `ImportError` with `ITK_USE_CUFFTW=ON` #4028

Open tbirdso opened 1 year ago

tbirdso commented 1 year ago

Description

ITKFFT fails to lazily import in ITK Python if built with ITK_USE_CUFFTW.

Steps to Reproduce

  1. Build ITK with ITK_USE_CUFFTW=ON and ITK_WRAP_PYTHON=ON
  2. Create a new Python virtual environment and add WrapITK.pth to site-packages
  3. Run the Python console and force ITKFFT to import by calling an FFT filter

Expected behavior

ITKFFT imports successfully.

Actual behavior

Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec  6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import itk
>>> itk.auto_progress(2)
>>> itk.ComplexToComplex1DFFTImageFilter
Loading ITKPyBase... done
Loading ITKCommon... done
Loading ITKStatistics... done
Loading ITKImageFilterBase... done
Loading ITKTransform... done
Loading ITKImageFunction... done
Loading ITKImageGrid... done
Loading ITKFFT... Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\repos\ITK-GPU-bld\Wrapping\Generators\Python\itk\support\lazy.py", line 138, in __getattribute__
    base.itk_load_swig_module(module, namespace)
  File "D:\repos\ITK-GPU-bld\Wrapping\Generators\Python\itk\support\base.py", line 132, in itk_load_swig_module
    l_module = loader.load(swig_module_name)
  File "D:\repos\ITK-GPU-bld\Wrapping\Generators\Python\itk\support\base.py", line 291, in load
    l_spec.loader.exec_module(l_module)  # pytype: disable=attribute-error
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "D:\repos\ITK-GPU-bld\Wrapping\Generators\Python\itk\support\..\ITKFFTPython.py", line 13, in <module>
    from . import _ITKFFTPython
ImportError: DLL load failed while importing _ITKFFTPython: The specified module could not be found.

Reproducibility

100%

Versions

ITK@815d0f0531 (main)

Environment

Windows 11 Python 3.10.9 CMake 3.24.3

Additional Information

CMakeCache.txt

Error persists after adding the NVIDIA GPU Computing Toolkit x64 directory to system PATH and restarting the console.

ITK FFT C++ tests all pass, the problem is limited to importing ITKFFT.

> ctest -C Release -R FFT
...
97% tests passed, 3 tests failed out of 94
...
Total Test time (real) =  16.51 sec

The following tests FAILED:
        3034 - PythonFFTImageFilterTest (Failed)
        3035 - PythonFFTObjectFactoryTest (Failed)
        3076 - PythonFFTConvolutionImageFilterTest (Failed)
Errors while running CTest
tbirdso commented 1 year ago

Note that https://github.com/InsightSoftwareConsortium/ITK/pull/4024 closed a similar issue (#4030) on Linux, but this issue seems to persist on Windows.