[vtkusers] Importing a local class in Python fails

Daniël Lacko lacko.daniel at gmail.com
Mon Apr 2 13:55:04 EDT 2012


It's taken me a while, but with the help of a colleague I've finally been
able to solve the problem. There where two issues with the compiled library.
Firstly, Python expects shared libraries to have the extension .pyd instead
of .dll (as well as an init function in the library) since version 2.5:
http://docs.python.org/extending/windows.html. However, the CMakeFile is
configured to use the default, which is .dll. However, when I changed the
file names I still couldn't import the function, because there was no init
function in the library. I checked the .pyd file and it did have an init
function, only it was for vtkLocalPython (where vtkLocal is the project
name) and not for libvtkLocalPython as generated by the makefile. Adding the
following lines to the CMakeLists.txt file resolved the problem:

IF(WIN32)
    SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "")
ENDIF(WIN32)

And under IF(VTK_WRAP_PYTHON):

 IF(WIN32)
    SET_TARGET_PROPERTIES(${LIB_NAME}Python PROPERTIES PREFIX "") 
    SET_TARGET_PROPERTIES(${LIB_NAME}Python PROPERTIES SUFFIX ".pyd")
 ENDIF(WIN32)

In the process of debugging this I briefly changed to a different Python
version, which caused problems when trying to compile this class. This was
solved by including the absolute path to the right Python include folder in
the CMakeLists.txt file:

INCLUDE_DIRECTORIES("C:/Python27/include/")

Hopefully this solution might prove useful for someone out there.

--
View this message in context: http://vtk.1045678.n5.nabble.com/Importing-a-local-class-in-Python-fails-tp5590447p5613186.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list