# Python wrapping (functions are missing in code generated)

**URL:** <https://discourse.vtk.org/t/python-wrapping-functions-are-missing-in-code-generated/5983>\
**Category:** Development\
**Created:** [June 11, 2021, 1:59pm UTC](https://discourse.vtk.org/t/python-wrapping-functions-are-missing-in-code-generated/5983 "2021-06-11T13:59:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)\
**Post date:** [June 11, 2021, 1:59pm UTC](https://discourse.vtk.org/t/python-wrapping-functions-are-missing-in-code-generated/5983/1 "2021-06-11T13:59:38Z")

</div>

Hi supporters

Just started a larger project based on the VTK pipeline and in relation to this I am creating a number of modules, which could potentially be future remote modules of VTK. I looked into how vtk-dicom was made - but ignored any stuff related to VTK prior to 9.0.

I use CMake and the new vtk\_module\_build and vtk\_module\_wrap macros. Under Linux, it works flawlessly and after adding VTK::CommonExecutionModel to the DEPENDS in my module file, the functions `GetOutput` and `GetOutputPort` was added to the wrapper of module deriving from vtkPolyDataAlgorithm. For the Windows build, the functions never appear in the Python wrappers.

Module file

```
NAME
  VTK::PCR
LIBRARY_NAME
  vtkPCR
GROUPS
  StandAlone
DEPENDS
  VTK::CommonCore
  VTK::CommonMath
  VTK::CommonTransforms
  VTK::CommonDataModel
  VTK::CommonExecutionModel
PRIVATE_DEPENDS
  VTK::CommonMisc
  VTK::CommonSystem
  VTK::FiltersCore
  VTK::FiltersSources
  VTK::vtksys
TEST_DEPENDS
  VTK::TestingCore

```

CMakeLists.txt in top folder (the relevant part)

```
vtk_module_scan(
  MODULE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Source/pcr.module" # What is scanned
  REQUEST_MODULES "VTK::PCR" # What is searched for
  PROVIDES_MODULES pcr_modules
  ENABLE_TESTS "${BUILD_TESTING}")

vtk_module_build(
  MODULES ${pcr_modules}
  INSTALL_EXPORT PCR
  ARCHIVE_DESTINATION "lib"
  HEADERS_DESTINATION "include/pcr${PCR_SHORT_VERSION}"
  CMAKE_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/vtk"
  LICENSE_DESTINATION "${CMAKE_INSTALL_LIBDIR}/vtk"
  HIERARCHY_DESTINATION "${CMAKE_INSTALL_LIBDIR}/vtk/hierarchy/${CMAKE_PROJECT_NAME}"
  LIBRARY_NAME_SUFFIX "${PCR_CUSTOM_LIBRARY_SUFFIX}"
  VERSION "${PCR_VERSION}"
  SOVERSION "1")

vtk_module_wrap_python(
  MODULES ${pcr_modules}
  INSTALL_EXPORT PCRPython
  PYTHON_PACKAGE "vtk.modules"
  CMAKE_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/vtk"
  LIBRARY_DESTINATION "${CMAKE_INSTALL_LIBDIR}"
  BUILD_STATIC OFF) # Python module is always dynamic built

```

CMakeLists.txt in the source folder

```
# When building as a module for VTK 8.90 or later
vtk_module_add_module(VTK::PCR
  CLASSES ${classes})
vtk_module_link(VTK::PCR
  PRIVATE
  VTK::CommonDataModel)

```

Thanks in advance  
Jens Munk

---

<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:** [June 11, 2021, 2:57pm UTC](https://discourse.vtk.org/t/python-wrapping-functions-are-missing-in-code-generated/5983/2 "2021-06-11T14:57:50Z")

</div>

> [@Jens\_Munk\_Hansen](#):
>
> ```auto
> vtk_module_link(VTK::PCR
> PRIVATE
> VTK::CommonDataModel)
> 
> ```

There’s no need to link manually; just make sure it is in `PRIVATE_DEPENDS`.

> [@Jens\_Munk\_Hansen](#):
>
> ```auto
> CMAKE_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/vtk"
> 
> ```

Your project is not VTK, so a different directory would be wise here. Maybe `vtkpcr`, but basically whatever you expect `find_package(vtkPCR)` or whatever to use.

> [@Jens\_Munk\_Hansen](#):
>
> which could potentially be future remote modules of VTK.

I’d rather not continue adding remote modules to VTK. Code is either in VTK or is not. Personally, I think just using VTK through `find_package(VTK)` should be sufficient for many VTK-using libraries.

As for the Python issue, does moving the manual link into the `vtk.module` help? If not, does the generated Python source code look sensible at least?

---

<div class="post-metadata">

**Author:** ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)\
**Post date:** [June 11, 2021, 3:36pm UTC](https://discourse.vtk.org/t/python-wrapping-functions-are-missing-in-code-generated/5983/3 "2021-06-11T15:36:50Z")

</div>

The manual link, I could safely remove. Moving the link into the .module file did not help.

I totally agree about remote modules. I have already decided to skip the possibility for using my library as a remote module.

The generated .cxx files for the class inheriting from vtkPolyDataAlgorithm is 33502 bytes (in Linux) where everything fine and 34679 bytes (in Windows), where the functions are missing in the wrapper. I think I will look into the contents of the generated files to figure out what is going on

Thanks for reaching out  
Jens

---

<div class="post-metadata">

**Author:** ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)\
**Post date:** [June 11, 2021, 4:43pm UTC](https://discourse.vtk.org/t/python-wrapping-functions-are-missing-in-code-generated/5983/5 "2021-06-11T16:43:38Z")

</div>

I found a solution. It appeared to be a DLL loading issue. Damn you Python 3.8+ on Windows. From Python 3.8 and onwards, you need to issue an `os.add_dll_directory(PATH)` in addition to adding the path to the system path, `sys.path.insert’. Also, I must have been loading some VTK python DLLs from what has been installed using pip rather than what I have compiled myself.

The recipe to make things work was the following:

1. Make sure the right DLLs are found

2. Make sure that the are loaded and no errors occur (some were silent)

3. Import my library

---

<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:** [June 11, 2021, 5:45pm UTC](https://discourse.vtk.org/t/python-wrapping-functions-are-missing-in-code-generated/5983/6 "2021-06-11T17:45:15Z")

</div>

Ah, yes. That…change. See [how VTK handles this](https://gitlab.kitware.com/vtk/vtk/-/blob/master/Wrapping/Python/vtkmodules/ __init__.py.in) and [the associated CMake code](https://gitlab.kitware.com/vtk/vtk/-/blob/master/Wrapping/Python/CMakeLists.txt) for this stuff. It’s a mess.
