<div dir="ltr">Hi Schuyler,<div><br></div><div>The PythonInit.cxx file provides the module's init function, so if the</div><div>module fails to load, my guess is that the name of the init function</div><div>does not match the name of the module.</div><div><br></div><div>Try adding these lines, to change the prefix/suffix of the shared</div><div>object:</div><div><br></div><div> set_target_properties(<span style="font-size:12.8px">${LIB_</span><span style="font-size:12.8px">NAME}Python</span> PROPERTIES PREFIX "")</div><div><div> if(WIN32)</div><div> set_target_properties(${LIB_NAME}Python PROPERTIES SUFFIX ".pyd")</div><div> endif()</div></div><div><br></div><div>I've written a set of macros for wrapping external projects, I hope to</div><div>release them soon. For reference, here is the code that I use to create</div><div>the python module:</div><div> <br><div><div> vtk_wrap_python3(${MODULE_PYTHON_NAME} LIB_PYTHON_SRCS "${_srcs}")</div><div> add_library(${LIB_PYTHON_NAME}</div><div> ${LIB_PYTHON_SRCS} ${LIB_PYTHON_EXTRA_SRCS}</div><div> ${LIB_HIERARCHY_STAMP})</div><div> set_target_properties(${LIB_PYTHON_NAME} PROPERTIES</div><div> POSITION_INDEPENDENT_CODE ON</div><div> OUTPUT_NAME "${LIB_PYTHON_OUTPUT_NAME}")</div><div> target_link_libraries(${LIB_PYTHON_NAME} LINK_PUBLIC ${_name} ${LIB_PYTHON_LIBS})</div></div><div><div> add_library(${MODULE_PYTHON_NAME} MODULE ${MODULE_PYTHON_NAME}Init.cxx)</div><div> set_target_properties(${MODULE_PYTHON_NAME} PROPERTIES PREFIX "")</div><div> if(WIN32)</div><div> set_target_properties(${MODULE_PYTHON_NAME} PROPERTIES SUFFIX ".pyd")</div><div> endif()</div><div> set_target_properties(${MODULE_PYTHON_NAME} PROPERTIES NO_SONAME 1)</div><div> target_link_libraries(${MODULE_PYTHON_NAME} ${LIB_PYTHON_NAME})</div><div><br></div><div> - David</div><div><br></div><div class="gmail_extra"><div class="gmail_quote">On Tue, Mar 29, 2016 at 9:23 AM, Schuyler Kylstra <span dir="ltr"><<a href="mailto:schuyler.kylstra@kitware.com" target="_blank">schuyler.kylstra@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Hi devs,<div><br></div><div>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:</div><div><div style="font-size:12.8px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><br>SET(SRCS</div><div> ....</div><div> )</div><div><br></div><div>SET_SOURCE_FILES_PROPERTIES(</div><div> <subset of SRCS></div><div> PROPERTIES</div><div> WRAP_EXCLUDE 1</div><div> WRAP_EXCLUDE_PYTHON 1</div><div> )</div><div><br></div><div>SET(VTK_LIBRARIES</div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div> <vtk libraries></div><div> )</div><div><br></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>SET(KIT_PYTHON_LIBRARIES ${VTK_LIBRARIES})</div><div><br></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">SET(LIBRARY_MODE "SHARED")</blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><br></div><div>INCLUDE(${VTK_CMAKE_DIR}/vtkWrapPython.cmake)</div><div>VTK_WRAP_PYTHON3(${LIB_NAME}Python PYTHON_SRCS "${SRCS}")</div><div>ADD_LIBRARY(${LIB_NAME}PythonD ${LIBRARY_MODE} ${PYTHON_SRCS})</div><div>ADD_LIBRARY(${LIB_NAME}Python MODULE ${LIB_NAME}PythonInit.cxx)</div><div><br></div><div>TARGET_LINK_LIBRARIES(${LIB_NAME}PythonD ${LIB_NAME})</div><div><br></div><div>FOREACH(c ${KIT_PYTHON_LIBRARIES})</div><div> TARGET_LINK_LIBRARIES(${LIB_NAME}PythonD ${c}PythonD)</div><div>ENDFOREACH(c)</div><div><br></div><div>TARGET_LINK_LIBRARIES(${LIB_NAME}Python ${LIB_NAME}PythonD)</div></blockquote></div><div style="font-size:12.8px"><div><br></div><div>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:</div></div><blockquote style="font-size:12.8px;margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><br></div><div>ImportError: dynamic module does not define init function</div></div><div><br></div></blockquote><span style="font-size:12.8px">Is there something I need to add to ensure that the init function is created?</span><span class=""><font color="#888888"><br clear="all"><div><br></div>-- <br><div><div dir="ltr">Schuyler Kylstra</div></div>
</font></span></div></div>
</blockquote></div><br></div></div></div></div>