# vtk python wrapper problem with compilation

**URL:** https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236
**Category:** Support
**Created:** [December 8, 2019, 8:24pm UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236 "2019-12-08T20:24:26Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Inna\_Daymand](https://discourse.vtk.org/user_avatar/discourse.vtk.org/inna_daymand/32/1172_2.png) [@Inna\_Daymand](https://discourse.vtk.org/u/Inna_Daymand)
#### Post date: [December 8, 2019, 8:24pm UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/1 "2019-12-08T20:24:26Z")

</div>

Hi everyone, I have a problem with compilation files for wrapping

# there is my cmake file

CMAKE\_MINIMUM\_REQUIRED(VERSION 3.3)

PROJECT(vtkExamplePython)

#C++11 flags  
set(CMAKE\_CXX\_FLAGS “${CMAKE\_CXX\_FLAGS} -Wall -std=c++11”)

FIND\_PACKAGE(VTK REQUIRED  
vtkCommonCore  
vtkCommonDataModel  
vtkWrappingPythonCore  
)

INCLUDE(${VTK\_USE\_FILE})

#Python and vtk wrapping  
include(vtkWrapPython)

SET(PYTHON\_LIBRARIES /Library/Frameworks/Python.framework/Versions/3.6/lib/libpython3.6.dylib)  
SET(PYTHON\_INCLUDE\_DIRS /Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m)  
INCLUDE\_DIRECTORIES(${PYTHON\_INCLUDE\_DIRS}

${VTK\_USE\_FILE})

#######################################  
#Building vtkExample  
ADD\_LIBRARY(vtkExample MODULE vtkExample.cpp)  
TARGET\_LINK\_LIBRARIES(vtkExample ${VTK\_LIBRARIES})  
if(APPLE)  
set\_target\_properties(vtkExample PROPERTIES SUFFIX “.so”)  
endif()  
#######################################  
#Wrapping vtkExample  
vtk\_wrap\_python3(vtkExamlePython vtkExamplePython\_SRCS vtkExample.cpp)

MESSAGE(“vtkExamplePython\_SRCS = ${vtkExamplePython\_SRCS}”)

add\_library(vtkExamplePythonD {vtkExamplePython\_SRCS} vtkExample.cpp) target\_link\_libraries(vtkExamplePythonD {VTK\_LIBRARIES}  
vtkWrappingPythonCore  
${VTK\_PYTHON\_LIBRARIES})

add\_library(vtkExamplePython MODULE vtkExamplePythonInit.data)  
set(VTK\_MODULES\_USED vtkCommonDataModel vtkCommonCore)  
set(VTK\_PYTHOND\_LIBS)  
foreach(TMP\_LIB {VTK\_MODULES\_USED}) set(VTK\_PYTHOND\_LIBS {VTK\_PYTHOND\_LIBS} ${TMP\_LIB}PythonD)  
endforeach()

target\_link\_libraries(vtkExamplePython vtkExamplePythonD ${VTK\_PYTHOND\_LIBS})

set\_target\_properties(vtkExamplePython PROPERTIES PREFIX “”)  
if(WIN32 AND NOT CYGWIN)  
set\_target\_properties(vtkExamplePython PROPERTIES SUFFIX “.pyd”)  
endif(WIN32 AND NOT CYGWIN)

==============================================================

This file compiles nice with cmake, but when I run make, I have an error

[11%] Python Wrapping - generating vtkExamplePythonInit.cxx  
make[2]: \*\*\* No rule to make target `/Users/idaymand/workspace/vtkExample/src/vtkExampleHierarchy', needed by`vtkExamplePython.cxx’. Stop.  
make[1]: \*\*\* [CMakeFiles/vtkExamplePythonD.dir/all] Error 2  
make: \*\*\* [all] Error 2

I make subfolder ./vtkExampleHierarchy in folder src, compile cmake again, and after that, run make and getting

[11%] Python Wrapping - generating vtkExamplePythonInit.cxx  
[22%] Python Wrapping - generating vtkExamplePython.cxx

And this state is staying long time without changes, till I do break process.

Help me please!!! What I do done not right?  
Thanks

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [December 9, 2019, 6:44am UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/2 "2019-12-09T06:44:23Z")

</div>

Which version of VTK are you using? For VTK 7 and 8, the solution in [this thread](https://discourse.vtk.org/t/wrapper-hierarchy-file/1552/19) might work for you. (Note that although the solution in that thread checks for `(${VTK_VERSION} VERSION_EQUAL "8.1")`, the same solution should work for 8.2).

---

<div class="post-metadata">

### Author: ![Inna\_Daymand](https://discourse.vtk.org/user_avatar/discourse.vtk.org/inna_daymand/32/1172_2.png) [@Inna\_Daymand](https://discourse.vtk.org/u/Inna_Daymand)
#### Post date: [December 9, 2019, 6:49am UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/3 "2019-12-09T06:49:44Z")

</div>

I am using 8.2\_0.4 version of vtk

---

<div class="post-metadata">

### Author: ![Inna\_Daymand](https://discourse.vtk.org/user_avatar/discourse.vtk.org/inna_daymand/32/1172_2.png) [@Inna\_Daymand](https://discourse.vtk.org/u/Inna_Daymand)
#### Post date: [December 9, 2019, 8:04am UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/4 "2019-12-09T08:04:41Z")

</div>

Hi David,  
Thank you for a help,

I inserted block with hierarchy before call vtk\_wrap\_python3 and now I have again a long time of compilation with message

make  
Scanning dependencies of target vtkGeodesicHierarchy  
[10%] For vtkGeodesic - updating vtkGeodesicHierarchy.txt

Help me please to solve this problem!  
Thanks

---

<div class="post-metadata">

### Author: ![Inna\_Daymand](https://discourse.vtk.org/user_avatar/discourse.vtk.org/inna_daymand/32/1172_2.png) [@Inna\_Daymand](https://discourse.vtk.org/u/Inna_Daymand)
#### Post date: [December 9, 2019, 8:22am UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/5 "2019-12-09T08:22:29Z")

</div>

[https://bitbucket.org/InnaDaymand/vtkgeodesic/src/master/src/CMakeLists.txt](https://bitbucket.org/InnaDaymand/vtkgeodesic/src/master/src/CMakeLists.txt)

this is link on my make file

also I your file vtkWrapHierarchy.cmake for include in my cmake file.

But I have a same effect - I can’t compile module

============================================================  
10:59:34 \*\*\*\* Build of configuration Default for project vtkGeodesic \*\*\*\*

make  
Scanning dependencies of target vtkGeodesicHierarchy  
[10%] For vtkGeodesic - updating vtkGeodesicHierarchy.txt

---

<div class="post-metadata">

### Author: ![Inna\_Daymand](https://discourse.vtk.org/user_avatar/discourse.vtk.org/inna_daymand/32/1172_2.png) [@Inna\_Daymand](https://discourse.vtk.org/u/Inna_Daymand)
#### Post date: [December 9, 2019, 12:12pm UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/6 "2019-12-09T12:12:42Z")

</div>

this commands hands up

/usr/local/Cellar/vtk/8.2.0\_4/bin/vtkWrapHierarchy-8.2 @vtkGeodesicHierarchy…args -o /Users/idaymand/workspace/vtkGeodesic/Debug/vtkGeodesicHierarchy.txt vtkGeodesicHierarchy.data

==========================  
file GeodesicHierarchy…args

-I"/usr/local/Cellar/vtk/8.2.0\_4/include/vtk-8.2"

-I"/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/include/python3.7m"

-I"/Users/idaymand/workspace/vtkGeodesic/src"

-I"/usr/local/Cellar/vtk/8.2.0\_4/lib/cmake/vtk-8.2/UseVTK.cmake"

-I"/usr/local/Cellar/vtk/8.2.0\_4/include/vtk-8.2"

=========================  
/Users/idaymand/workspace/vtkGeodesic/Debug/vtkGeodesicHierarchy.txt  
this file is not exist

=========================  
file vtkGeodesicHierarchy.data

/Users/idaymand/workspace/vtkGeodesic/src/vtkGeodesic.h;vtkGeodesic

=========================

I am right understand, that file  
/Users/idaymand/workspace/vtkGeodesic/Debug/vtkGeodesicHierarchy.txt  
is output?

Thanks

---

<div class="post-metadata">

### Author: ![Inna\_Daymand](https://discourse.vtk.org/user_avatar/discourse.vtk.org/inna_daymand/32/1172_2.png) [@Inna\_Daymand](https://discourse.vtk.org/u/Inna_Daymand)
#### Post date: [December 9, 2019, 9:59pm UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/7 "2019-12-09T21:59:57Z")

</div>

Hi David,  
I researched my problem with stand up of vtkWrapHierarchy-8.2 by process of parsing headers, and I think, that I have a problem with description of head file.

Below is link on my header file, can you look please, may be something need add?

[https://bitbucket.org/InnaDaymand/vtkgeodesic/src/master/src/vtkGeodesic.h](https://bitbucket.org/InnaDaymand/vtkgeodesic/src/master/src/vtkGeodesic.h)

Thanks

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [December 10, 2019, 12:30am UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/8 "2019-12-10T00:30:12Z")

</div>

Hi Inna,

You are correct that there is a problem parsing the header, it is triggered by this code:

```
","<<axes_x.GetY();

```

This is very strange, because it works fine if spaces are added:

```
"," << axes_x.GetY();

```

It’s a little mystery that I can investigate.

For wrapping with VTK 8.2, see the cmake code below. Note that I removed “MODULE” from the first add\_library(). The only thing that should be built as a module is the python module, vtkGeodesicPython.so (or .pyd on Windows).

The `PROPERTY POSITION_INDEPENDENT_CODE ON` is needed in case you are doing a static build on a 64-bit linux (or mac) system and linking the static libraries to the python module (it enables the ‘-fPIC’ option of the compiler).

```auto
#######################################
# Building vtkGeodesic
add_library(${LIB_NAME} vtkGeodesic.cpp)
target_link_libraries(${LIB_NAME} ${VTK_LIBRARIES})

#######################################
# Wrapping vtkGeodesic
set(MODULE_HIERARCHY_NAME ${LIB_NAME}Hierarchy)
# All libs mentioned here must be listed in the find_package(VTK ...) 
set(${LIB_NAME}_LINK_DEPENDS vtkCommonCore vtkCommonDataModel)
set(${LIB_NAME}_WRAP_DEPENDS vtkCommonCore vtkCommonDataModel)

set(OTHER_HIERARCHY_FILES)
foreach(dep ${${LIB_NAME}_LINK_DEPENDS})
  list(APPEND OTHER_HIERARCHY_FILES "${${dep}_WRAP_HIERARCHY_FILE}")
endforeach()

include(vtkWrapHierarchy)
vtk_wrap_hierarchy(${LIB_NAME} ${CMAKE_CURRENT_BINARY_DIR} "${LIB_SRCS}")
set(KIT_HIERARCHY_FILE ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_HIERARCHY_NAME}.txt)
set(LIB_HIERARCHY_STAMP ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_HIERARCHY_NAME}.stamp.txt)

vtk_wrap_python3(${LIB_NAME}Python ${LIB_NAME}Python_SRCS vtkGeodesic.cpp)

MESSAGE("vtkGeodesicPython_SRCS = ${vtkGeodesicPython_SRCS}")

add_library(${LIB_NAME}PythonD ${${LIB_NAME}Python_SRCS} vtkGeodesic.cpp)
set_property(TARGET ${LIB_NAME}PythonD
        PROPERTY POSITION_INDEPENDENT_CODE ON)

target_link_libraries(${LIB_NAME}PythonD
        ${VTK_LIBRARIES}
        vtkWrappingPythonCore
        ${VTK_PYTHON_LIBRARIES})

add_library(${LIB_NAME}Python MODULE ${LIB_NAME}PythonInit.cxx)

set(VTK_MODULES_USED vtkCommonDataModel vtkCommonCore)

set(VTK_PYTHOND_LIBS)

foreach(TMP_LIB ${VTK_MODULES_USED})
   set(VTK_PYTHOND_LIBS ${VTK_PYTHOND_LIBS} ${TMP_LIB}PythonD)
endforeach()

target_link_libraries(${LIB_NAME}Python ${LIB_NAME}PythonD ${VTK_PYTHOND_LIBS})

set_target_properties(${LIB_NAME}Python PROPERTIES PREFIX "")
if(WIN32 AND NOT CYGWIN)
    set_target_properties(${LIB_NAME}Python PROPERTIES SUFFIX ".pyd")
endif(WIN32 AND NOT CYGWIN)

```

---

<div class="post-metadata">

### Author: ![Inna\_Daymand](https://discourse.vtk.org/user_avatar/discourse.vtk.org/inna_daymand/32/1172_2.png) [@Inna\_Daymand](https://discourse.vtk.org/u/Inna_Daymand)
#### Post date: [December 10, 2019, 4:07am UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/9 "2019-12-10T04:07:36Z")

</div>

Hi David,  
thank you very mush for your help, I got a file vtkGeodesicPython.so.

But in Python

**import vtkGeodesicPython**

does not work, symbol not resolved before running.

I work with Python 3.6, may be problem in this?

I tried to find where I am connecting version of library Python 3.7 in my cmake file, but not found.

I saved this file in subfolder ./lib, this subfolder is registered in PYTHONPATH of project.

Help me please to understand what I do not right.

Thanks

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [December 10, 2019, 4:32am UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/10 "2019-12-10T04:32:46Z")

</div>

What symbol is not resolved? How is your VTK installed?

---

<div class="post-metadata">

### Author: ![Inna\_Daymand](https://discourse.vtk.org/user_avatar/discourse.vtk.org/inna_daymand/32/1172_2.png) [@Inna\_Daymand](https://discourse.vtk.org/u/Inna_Daymand)
#### Post date: [December 10, 2019, 5:46am UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/11 "2019-12-10T05:46:45Z")

</div>

I am working on the Mac Sierra, in Eclipse with plugin PyDev, and using Python 3.6

I installed VTK with homebrew (homebrew install vtk).

I write  
import vtkGeodesicPython

in python file, and I am getting information, that import not resolved. If I trace this line in debug, my Python is crashing.

Also need note, that I haven’t\_\_\_\_init\_\_.py I didn’t get it as result of compilation.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [December 10, 2019, 1:41pm UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/12 "2019-12-10T13:41:02Z")

</div>

According to the homebrew page, their VTK package uses Python 3.7.5. So if you want to use homebrew’s VTK, you must use homebrew’s Python 3.7.

If your project requires Python 3.6, then you will have to build VTK with Python 3.6.

---

<div class="post-metadata">

### Author: ![Inna\_Daymand](https://discourse.vtk.org/user_avatar/discourse.vtk.org/inna_daymand/32/1172_2.png) [@Inna\_Daymand](https://discourse.vtk.org/u/Inna_Daymand)
#### Post date: [December 10, 2019, 5:50pm UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/13 "2019-12-10T17:50:36Z")

</div>

Hi David,

I researched a question with version, and I have following data

1. With Python 3.6 is delivering vtk 8.1.2 for mac os sierra
2. on the site download VTK there is only version 8.2.0 or 7.1.1 and lower.

What should I do? Download for c version of VTK 8.2.0 and use headers from it, but compile with library 8.1.2 from python?

Thanks a lot

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [December 10, 2019, 5:55pm UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/14 "2019-12-10T17:55:35Z")

</div>

You should use the Python 3.7 and VTK that comes with Homebrew, since you have already installed it.

Why are you using Python 3.6?

---

<div class="post-metadata">

### Author: ![Inna\_Daymand](https://discourse.vtk.org/user_avatar/discourse.vtk.org/inna_daymand/32/1172_2.png) [@Inna\_Daymand](https://discourse.vtk.org/u/Inna_Daymand)
#### Post date: [December 10, 2019, 6:07pm UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/15 "2019-12-10T18:07:37Z")

</div>

I am working in project that uses python 3.6 with vtk.

This is big project, and my job in it - is doing wrapper from c++ to python for realisation of critical important in terms of speed algorithm

I can not change version of python

May be, I can use headers from vtk 8.2 from homebrew, but by link include libraries from vtk 8.1.2?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [December 10, 2019, 6:15pm UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/16 "2019-12-10T18:15:09Z")

</div>

Then your only choice is to download the VTK 8.2 source code and build VTK yourself.

---

<div class="post-metadata">

### Author: ![Inna\_Daymand](https://discourse.vtk.org/user_avatar/discourse.vtk.org/inna_daymand/32/1172_2.png) [@Inna\_Daymand](https://discourse.vtk.org/u/Inna_Daymand)
#### Post date: [December 10, 2019, 6:16pm UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/17 "2019-12-10T18:16:03Z")

</div>

May be, I can use headers from vtk 8.2 from homebrew, but by link include libraries from vtk 8.1.2?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [December 10, 2019, 6:20pm UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/18 "2019-12-10T18:20:28Z")

</div>

No, you cannot use the VTK 8.2 headers with VTK 8.1.2 libraries.

---

<div class="post-metadata">

### Author: ![Inna\_Daymand](https://discourse.vtk.org/user_avatar/discourse.vtk.org/inna_daymand/32/1172_2.png) [@Inna\_Daymand](https://discourse.vtk.org/u/Inna_Daymand)
#### Post date: [December 10, 2019, 6:33pm UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/19 "2019-12-10T18:33:53Z")

</div>

One more question,

if I build VTK myself and build library with it, will i can use vtk 8.1.2 package for python 3.6 with my library? Or it must be use only VTK which i build myself?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [December 10, 2019, 6:40pm UTC](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236/20 "2019-12-10T18:40:22Z")

</div>

Your library can only be used with the version of VTK that you use to build it.

[Next page](https://discourse.vtk.org/t/vtk-python-wrapper-problem-with-compilation/2236.md?page=2)
