Skip to content

BUG: Register VTK's DLL directory at import itk on Windows - #7059

Merged
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
dzenanz:importVTKfix
Nov 1, 2026
Merged

hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
dzenanz:importVTKfix

Conversation

@dzenanz

@dzenanz dzenanz commented Oct 31, 2026

Copy link
Copy Markdown
Member

On Windows, import itk; itk.force_load() failed with DLL load failed while importing _ITKVtkGluePython against a multi-config VTK build tree. ITKVtkGlueConfig.py now registers VTK's DLL directory, so users don't need os.add_dll_directory or an import vtkmodules first.

Root cause

Python >= 3.8 ignores PATH for an extension's dependent DLLs. vtkmodules only registers <prefix>/bin, but Visual Studio builds of VTK put their DLLs in bin/<config>. A complementary VTK change adds those directories to vtkmodules/_build_paths.py. The two changes don't conflict: registering the same directory twice is harmless.

import itk imports every itk/Configuration/*Config.py, so a new ITK_WRAP_PYTHON_CONFIGURATION_PREAMBLE placeholder in ModuleConfig.py.in runs before VtkGlue or vtkmodules loads. Modules that leave it empty generate the same file as before. VtkGlue sets it on Windows only, to the directory of VTK::CommonCore for CMAKE_BUILD_TYPE, or for Release in multi-config builds.

No CI configuration enables Module_ITKVtkGlue, which is why CI didn't catch this.

AI assistance
  • Claude Code diagnosed the failure and wrote the change and test adjustments.
  • Local Windows/VS2022 Release build with Python wrapping and VTK_DIR pointing to a VTK 9.7 VS2022 build tree: PythonVtkGlue*, PythonFindEmptyClasses, PythonGetNameOfClass, PythonTiming, PythonBuildOptions, PythonVerify*APIConsistency, PythonTypeTest and PythonExtrasTest all pass (11/11).

🤖 Generated with Claude Code

@github-actions github-actions Bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots area:Python wrapping Python bindings for a class type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Bridge Issues affecting the Bridge module labels Oct 31, 2026

@hjmjohnson hjmjohnson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dzenanz
dzenanz marked this pull request as ready for review November 1, 2026 14:24
@greptile-apps

greptile-apps Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change reaches Windows users of Python-wrapped ITKVtkGlue.

Fix the generated path quoting before merging; a valid Windows directory can currently prevent ITK from importing.

Findings

  1. P1 Apostrophes break ITK imports ▶

Summary

Adds a per-module Python preamble so Windows builds register VTK's DLL directory during import itk.

  • ITK registers VTK’s DLL folder before loading its Python modules.

Reviews (1) · Last reviewed commit: "BUG: Register VTK's DLL directory at imp..." · Reviewed by Greptile

Python >= 3.8 ignores PATH for an extension's dependent DLLs, so
_ITKVtkGluePython failed to load and itk.force_load() raised ImportError.
vtkmodules registers only <prefix>/bin, which misses the bin/<config>
directory of a multi-config VTK build tree.

ITKVtkGlueConfig.py, which import itk loads, now adds the directory of
VTK::CommonCore, so it is registered before VtkGlue or vtkmodules loads.
@hjmjohnson
hjmjohnson merged commit fc63666 into InsightSoftwareConsortium:main Nov 1, 2026
19 checks passed
@dzenanz
dzenanz deleted the importVTKfix branch November 1, 2026 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Bridge Issues affecting the Bridge module area:Python wrapping Python bindings for a class type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants