Skip to content

Commit 54bea15

Browse files
committed
windows: Add Visual Studio runtime libraries to itk-core
This addresses the error: import _ITKPyBasePython ImportError: DLL load failed: On Windows when: Visual Studio is not installed on the system, or the vc_redist.x64.exe Visual Studio C++ redistributables are not installed, or Anaconda is not used (Anaconda ships the redistributable dll's in a vc2015_runtime package when Python is installed). With DependencyWalker, we can observe that the _ITKPyBasePython.pyd dll requires vcruntime140.dll, vcruntime140_1.dll, and msvcp140.dll. CPython from python.org ships with vcruntime140.dll for Python 3.5, 3.6, 3.7, and 3.8. Experimentally, if we add msvcp140.dll to the itk/ package directory, the import succeeds. This patch adds all three libraries plus an additional library with the CMake InstallRequiredSystemLibraries module to the itk-core package. For more information, see this blog post by Steve Dower: https://stevedower.id.au/blog/building-for-python-3-5-part-two Thanks to Jean-Christophe Fillion-Robin for the helpful discussion.
1 parent 1e865ce commit 54bea15

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.3)
22

3-
project(ITKPythonPackage NONE)
3+
project(ITKPythonPackage CXX)
44

55
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
66
include(ITKPythonPackage)
@@ -488,6 +488,14 @@ else()
488488

489489
endif()
490490

491+
if(MSVC AND ITKPythonPackage_WHEEL_NAME STREQUAL "itk-core")
492+
message(STATUS "Adding install rules for compiler runtime libraries")
493+
# Put the runtime libraries next to the "itk/_*.pyd" C-extensions so they
494+
# are found.
495+
set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION "itk")
496+
include(InstallRequiredSystemLibraries)
497+
endif()
498+
491499
#-----------------------------------------------------------------------------
492500
# Install ITK components
493501
message(STATUS "Adding install rules for components:")

0 commit comments

Comments
 (0)