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

**URL:** https://discourse.vtk.org/t/vtk-python-wheel-cannot-import-dlls-or-doesnt-generate-pyi/13769
**Category:** Support
**Tags:** python
**Created:** [April 22, 2024, 11:14am UTC](https://discourse.vtk.org/t/vtk-python-wheel-cannot-import-dlls-or-doesnt-generate-pyi/13769 "2024-04-22T11:14:07Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Sai\_Chaitanya\_Rodda](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sai_chaitanya_rodda/32/7139_2.png) [@Sai\_Chaitanya\_Rodda](https://discourse.vtk.org/u/Sai_Chaitanya_Rodda)
#### Post date: [April 22, 2024, 11:14am UTC](https://discourse.vtk.org/t/vtk-python-wheel-cannot-import-dlls-or-doesnt-generate-pyi/13769/1 "2024-04-22T11:14:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [April 27, 2024, 6:59pm UTC](https://discourse.vtk.org/t/vtk-python-wheel-cannot-import-dlls-or-doesnt-generate-pyi/13769/2 "2024-04-27T18:59:02Z")

</div>

You should use `delvewheel` [like VTK does](https://gitlab.kitware.com/vtk/vtk/-/blob/90ef0a2a28c7647adccb5e4687c62e6846a238b7/.gitlab/os-windows.yml#L306-308).

---

<div class="post-metadata">

### Author: ![Sai\_Chaitanya\_Rodda](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sai_chaitanya_rodda/32/7139_2.png) [@Sai\_Chaitanya\_Rodda](https://discourse.vtk.org/u/Sai_Chaitanya_Rodda)
#### Post date: [April 27, 2024, 8:43pm UTC](https://discourse.vtk.org/t/vtk-python-wheel-cannot-import-dlls-or-doesnt-generate-pyi/13769/3 "2024-04-27T20:43:40Z")

</div>

Thank you very much Ben! It is working.
