I am building VTK from source on Windows 10 using Ninja. After building, however, I cannot import vtk
as it cannot import the _build_paths
. Here is my setup:
Hardware
OS: Windows 10 Enterprise, x64-bit, Build 1909
CPU: 2x Intel(R) Xeon(R) Gold 6248R
Disk: 2TB NVMe M.2 SSD
RAM: 192 GB DDR4
Compute GPUs: 2x NVIDIA Quadro RTX8000
Display GPU: 1x NVIDIA Quadro RTX4000
Software
Ninja: 1.10.2 (Extracted from ninja-win.zip into C:\WINDOWS
)
Visual Studio: Visual Studio 16 2019 Community
Windows SDK: 10.0.19041.0, targeting 10.0.18363
Python: 3.8.10 x64-bit
CMake: 3.21.1 (I use CMake-GUI
)
vcpkg: 2021-08-12
VTK Source: Master branch, cloned as follows:
> cd C:\VTK
> git clone --recursive https://gitlab.kitware.com/vtk/vtk.git src
TBB: tbb2018_20170919oss
Steps to Reproduce
- Open
x64 Native Tools Command Prompt for VS 2019
- Make
C:\VTK
folder and git clone source into subfoldersrc
as shown above - Start
CMake-GUI
by runningcmake-gui
- In
CMake-GUI
, chooseC:\VTK\src
for the source folder andC:\VTK
for the build folder - Press
Configure
and chooseNinja
as the build tool - Change the following settings:
VTK_RELOCATABLE_INSTALL OFF
VTK_GROUP_ENABLE_Imaging WANT
VTK_GROUP_ENABLE_MPI WANT
VTK_GROUP_ENABLE_Qt WANT
VTK_GROUP_ENABLE_Rendering WANT
VTK_GROUP_ENABLE_StandAlone WANT
VTK_MAX_THREADS 96
VTK_MPI_NUMPROCS 48
VTK_PYTHON_VERSION 3
VTK_QT_VERSION 5
VTK_SMP_IMPLEMENTATION_TYPE TBB
VTK_USE_MPI ON
VTK_WRAP_PYTHON ON
Python3_EXECUTABLE C:/Program Files/Python38/python.exe
Python3_INCLUDE_DIR C:/Program Files/Python38/include
Python3_LIBRARY C:/Program Files/Python38/libs/python38.lib
MPIEXEC_MAX_NUMPROCS 48
MPI_C_HEADER_DIR C:/Program Files (x86)/Microsoft SDKs/MPI/Include
MPI_msmpi_LIBRARY C:/Program Files (x86)/Microsoft SDKs/MPI/Lib/x64/msmpi.lib
CMAKE_CXX_MP_FLAG ON
CMAKE_BUILD_TYPE Release
CMAKE_INSTALL_PREFIX C:/VTK
TBB_DIR C:/tbb2018_20170919oss/cmake
- Reconfigure and then press
Generate
. Only 1 warning appears duringConfigure
, which seems harmless
CMake Warning (dev) at GUISupport/QtQuick/qml/CMakeLists.txt:100 (message):
Qt5 is configured in both Debug and Release modes. Due to Qt issue 47774
(https://bugreports.qt.io/browse/QTBUG-47774), skipping generation of
qmltypes file. Using the one provided with the source tree instead.
This warning is for project developers. Use -Wno-dev to suppress it.
- Back in
x64 Native Tools Command Prompt for VS 2019
, runninja
fromC:\VTK
directory - After build completes, run
ninja install
- Add the following to
PYTHON_PATH
andPATH
environment variableS:
C:\VTK
C:\VTK\bin
C:\VTK\bin\Lib\site-packages\
C:\VTK\include
C:\VTK\include\vtk-9.0\
C:\VTK\lib
C:\VTK\lib\cmake
- Open a new python interpreter session in
PowerShell
and attempt to importvtk
Problem
Trying to import vtk in a Python38 interpreter started in PowerShell yields the following error:
❯ py
Python 3.8.10 (tags/v3.8.10:3d8993a, May 3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import vtk
Traceback (most recent call last):
File "C:\VTK\bin\Lib\site-packages\vtkmodules\__init__.py", line 54, in <module>
from . import vtkCommonCore
ImportError: DLL load failed while importing vtkCommonCore: The specified procedure could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\VTK\bin\Lib\site-packages\vtk.py", line 31, in <module>
all_m = importlib.import_module('vtkmodules.all')
File "C:\Program Files\Python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\VTK\bin\Lib\site-packages\vtkmodules\__init__.py", line 56, in <module>
import _vtkmodules_static
ModuleNotFoundError: No module named '_vtkmodules_static'
>>>
Using print
statements, I’ve narrowed down the issue to the following line in C:\VTK\bin\Lib\site-packages\vtkmodules\__init__.py
giving an import error
from . import _build_paths
e.g. If I put corresponding print statements in the _windows_dll_path
function of C:\VTK\C:\VTK\bin\Lib\site-packages\vtkmodules\__init__.py
like so:
# Build tree support.
try:
print("Try import...")
from . import _build_paths
print("I worked!")
# Add any paths needed for the build tree.
for path in _build_paths.paths:
if os.path.exists(path):
_ = os.add_dll_directory(path)
except ImportError:
# Relocatable install tree (or non-Windows).
pass
the result is
❯ py
Python 3.8.10 (tags/v3.8.10:3d8993a, May 3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import vtk
Try import...
Traceback (most recent call last):
File "C:\VTK\bin\Lib\site-packages\vtkmodules\__init__.py", line 54, in <module>
from . import vtkCommonCore
ImportError: DLL load failed while importing vtkCommonCore: The specified procedure could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\VTK\bin\Lib\site-packages\vtk.py", line 31, in <module>
all_m = importlib.import_module('vtkmodules.all')
File "C:\Program Files\Python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\VTK\bin\Lib\site-packages\vtkmodules\__init__.py", line 56, in <module>
import _vtkmodules_static
ModuleNotFoundError: No module named '_vtkmodules_static'
>>>
How can I fix this problem?