VTK build fails on Windows when Python type hints are requested (VTK_BUILD_PYI_FILES)

Hello,

I’m building VTK 9.5.2 on Windows and all is well until I request Python type hints with VTK_BUILD_PYI_FILES.

The build fails with the following error

Severity Code Description Project File Line Suppression State Details
Error MSB8066 Custom build for ‘E:\Software\vtk\build\CMakeFiles\05cf3c8b85c8aaf14b881db917599f06\vtkCommonCore.pyi.rule;E:\Software\vtk\build\CMakeFiles\ab3ac9675c28ecbf447909429c8c7300\vtkpythonmodules_pyi.rule;E:\Software\vtk\source\CMakeLists.txt’ exited with code 1. vtkpythonmodules_pyi C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets 254

Any ideas on what could be wrong here?

Thanks in advance,

Doug

I did a test build with the Visual Studio generator to see what is going on. Scrolling up through the build log provides the actual error:

    File "E:\Software\vtk-build\lib\site-packages\vtkmodules\generate_pyi.py", line 38, in <module>
      from vtkmodules.vtkCommonCore import vtkObjectBase, vtkSOADataArrayTemplate
  ImportError: DLL load failed while importing vtkCommonCore: The specified module could not be found.

Seems the issue is in vtkmodules/__init__.py, which assumes the VTK DLLs are in vtk-build/bin. For the Visual Studio generators, the DLLs are actually in vtk-build/bin/Release or vtk-build/bin/Debug. As a result, the vtk-python modules are unable to load the VTK DLLs from the build tree.

There are two work-arounds that I can think of:

  1. Intsead of setting VTK_BUILD_PYI_FILES during configuration, do a normal VTK build followed by install and then run python -m vtkmodules.generate_pyi manually. Since the DLLs are in “bin/” in the install tree (e.g. not in “bin/Release/” like in the build tree), vtk-python will be able to use the installed DLLs.
  2. The easiest solution is probably to use Ninja instead of MSBuild, since Ninja doesn’t use Release & Debug subdirectories.