VTK python wheel cannot import dlls or doesn't generate pyi

Hello All,

I am currently building VTK from source with flag VTK_WHEEL_BUILD as on to make my own python wheel. However, the python wheel created is not usable. I have to either specify the vtk dll paths in my python program using os.add_dll_directory() or generate pyi files manually using the generate_pyi.py file located in the vtkmodules folder to make it work.

I will go through the steps I have followed to make the wheel:

  1. Firstly, I set up the necessary flag VTK_WHEEL_BUILD as ON in CMAKE GUI and configure and generate my vtk solution file using Visual studio 2022.

  2. Second, I use the solution file and make the build for my source.

  3. This build will create a setup.py file in my build directory.

  4. Then I run the command python setup.py bdist_wheel to generate the wheel file which will be created in the build\dist directory. At this point I also have another build inside my build directory where my vtkmodules folder and vtk.py file reside.

  5. I then proceed to install the wheel in my venv using pip install pythonWheel.whl.

  6. The installed vtk library is not usable unless I specify the vtk dlls path in my python file using os.add_dll_directory() or generate pyi files manually (in the venv).

I tried a couple of trial and error as follows,

  1. I have also tried to add vtk module dll folder path (which is located in the bin of my vtk build directory) to VTK_DLL_PATHS in CMAKE. This did not worked, gave same issue.
  2. I have the set the flag VTK_BUILD_PYI_FILES to on in CMAKE and rebuild the solution file. However, this gave the error as “DLL files cannot be opened”.

Please let me know where did I go wrong or have I missed something.

PS: The wheel build is made for VTK 9.3 using python 3.9.13

1 Like

You should use delvewheel like VTK does.

2 Likes

Thank you very much Ben! It is working.