[vtk-developers] python wrapping with VTK 7

Schuyler Kylstra schuyler.kylstra at kitware.com
Wed Mar 30 15:02:20 EDT 2016


Thanks David! That fixed it.

On Tue, Mar 29, 2016 at 5:16 PM, David Gobbi <david.gobbi at gmail.com> wrote:

> Hi Schuyler,
>
> The PythonInit.cxx file provides the module's init function, so if the
> module fails to load, my guess is that the name of the init function
> does not match the name of the module.
>
> Try adding these lines, to change the prefix/suffix of the shared
> object:
>
>     set_target_properties(${LIB_NAME}Python PROPERTIES PREFIX "")
>     if(WIN32)
>       set_target_properties(${LIB_NAME}Python PROPERTIES SUFFIX ".pyd")
>     endif()
>
> I've written a set of macros for wrapping external projects, I hope to
> release them soon.  For reference, here is the code that I use to create
> the python module:
>
>     vtk_wrap_python3(${MODULE_PYTHON_NAME} LIB_PYTHON_SRCS "${_srcs}")
>     add_library(${LIB_PYTHON_NAME}
>       ${LIB_PYTHON_SRCS} ${LIB_PYTHON_EXTRA_SRCS}
>       ${LIB_HIERARCHY_STAMP})
>     set_target_properties(${LIB_PYTHON_NAME} PROPERTIES
>       POSITION_INDEPENDENT_CODE ON
>       OUTPUT_NAME "${LIB_PYTHON_OUTPUT_NAME}")
>     target_link_libraries(${LIB_PYTHON_NAME} LINK_PUBLIC ${_name}
> ${LIB_PYTHON_LIBS})
>     add_library(${MODULE_PYTHON_NAME} MODULE ${MODULE_PYTHON_NAME}Init.cxx)
>     set_target_properties(${MODULE_PYTHON_NAME} PROPERTIES PREFIX "")
>     if(WIN32)
>       set_target_properties(${MODULE_PYTHON_NAME} PROPERTIES SUFFIX ".pyd")
>     endif()
>     set_target_properties(${MODULE_PYTHON_NAME} PROPERTIES NO_SONAME 1)
>     target_link_libraries(${MODULE_PYTHON_NAME} ${LIB_PYTHON_NAME})
>
>  - David
>
> On Tue, Mar 29, 2016 at 9:23 AM, Schuyler Kylstra <
> schuyler.kylstra at kitware.com> wrote:
>
>> Hi devs,
>>
>> I'm working on a VTK 7 based project that I'm trying to wrap in python.
>> I'm stuck at a point where the project builds but the python library cannot
>> be included. I'm doing the following in my CMakeLists.txt file:
>>
>>
>> SET(SRCS
>>   ....
>>   )
>>
>> SET_SOURCE_FILES_PROPERTIES(
>>   <subset of SRCS>
>>   PROPERTIES
>>   WRAP_EXCLUDE 1
>>   WRAP_EXCLUDE_PYTHON 1
>>   )
>>
>> SET(VTK_LIBRARIES
>>
>>    <vtk libraries>
>>    )
>>
>> SET(KIT_PYTHON_LIBRARIES ${VTK_LIBRARIES})
>>
>> SET(LIBRARY_MODE "SHARED")
>>
>>
>> INCLUDE(${VTK_CMAKE_DIR}/vtkWrapPython.cmake)
>> VTK_WRAP_PYTHON3(${LIB_NAME}Python PYTHON_SRCS "${SRCS}")
>> ADD_LIBRARY(${LIB_NAME}PythonD ${LIBRARY_MODE} ${PYTHON_SRCS})
>> ADD_LIBRARY(${LIB_NAME}Python MODULE ${LIB_NAME}PythonInit.cxx)
>>
>> TARGET_LINK_LIBRARIES(${LIB_NAME}PythonD ${LIB_NAME})
>>
>> FOREACH(c ${KIT_PYTHON_LIBRARIES})
>>   TARGET_LINK_LIBRARIES(${LIB_NAME}PythonD ${c}PythonD)
>> ENDFOREACH(c)
>>
>> TARGET_LINK_LIBRARIES(${LIB_NAME}Python ${LIB_NAME}PythonD)
>>
>>
>> As I said before, this all builds without error but when I try to run any
>> python script that includes the library I get the following error:
>>
>>
>> ImportError: dynamic module does not define init function
>>
>> Is there something I need to add to ensure that the init function is
>> created?
>>
>> --
>> Schuyler Kylstra
>>
>
>


-- 
Schuyler Kylstra
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20160330/fea5cea0/attachment.html>


More information about the vtk-developers mailing list