"ImportError: DLL load failed" error when trying to import vtk

I’m running python 3.10.9 on Windows 10 Pro. Steps to reproduce: I create a new virtualenv with python -m venv env then run pip install vtk, which installs vtk version 9.2.6. Then, when I try to simply import vtk in the python shell, I get this error:

File “C:\Users[my name]\Documents\DebuggingVTK\env\lib\site-packages\vtk.py”, line 4, in
from vtkmodules.vtkCommonCore import *
ImportError: DLL load failed while importing vtkCommonCore: The specified module could not be found.

I’ve tried running os.add_dll_directory(r'C:\Users\[my name]\Documents\DebuggingVTK\env\lib\site-packages\vtkmodules'), but that didn’t change anything. I’ve also tried adding this directory to PATH and PYTHONPATH.

I could possibly build vtk from source, but the project is set up to pip install it from requirements.txt, plus other people might have this issue, so it’d be great to figure out if there’s a workaround this way.

I really appreciate any help. I’ve been stuck on this all day.

VTK should be doing os.add_dll_directory on its own already. Could you use procmon to see what DLL is failing to load (you’ll need to set up some filters to make it “useful” for this). I don’t know if Python provides better error messages (maybe 3.11 does?).

Sorry for the late reply. Upgrading to vtk 9.3.0 fixed my problem. Thanks for the suggestion!