DLL load failed while importing vtkRenderingOpenVR

After building VTK (latest release branch) on Windows succussfully and generating a wheel, when I try to import vtk in Python, I get an error loading the DLL for vtkRenderingOpenVR:

>>> import vtk
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\banes\miniconda3\envs\vtkvr\lib\site-packages\vtk.py", line 31, in <module>
    all_m = importlib.import_module('vtkmodules.all')
  File "C:\Users\banes\miniconda3\envs\vtkvr\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\banes\miniconda3\envs\vtkvr\lib\site-packages\vtkmodules\all.py", line 50, in <module>
    from .vtkRenderingOpenVR import *
ImportError: DLL load failed while importing vtkRenderingOpenVR: The specified module could not be found.

Any tips on how to fix this?

I see vtkRenderingOpenVR-9.2.dll in vtkmodules so I’m not too sure what’s going wrong.

~This is Python 3.9 so maybe I should upgrade to 3.10 or 3.11 to maybe get more insight into what’s failing to load~ upgrading to Python 3.11 made no difference

Aha! Copy/pasting openvr_api.dll into the install vtkmodules path fixed the issue. I wonder if there’s a way I can easily include that in the wheel?

I dont know much about the way wheel are handled (@ben.boeckel ), but you could add the dll location to your PATH instead.

Python 3.9+ require os.add_dll_directory(). You can add it to the VTK’s VTK_DLL_PATHS CMake variable, but that pins OpenVR to that location on whatever wants to import everything from VTK. I have no idea what packaging tooling (if any) exists to copy required DLLs into the wheel.