[vtkusers] Importing a local class in Python fails

David Gobbi david.gobbi at gmail.com
Mon Apr 2 14:17:40 EDT 2012


Hi Daniel,

Yes, what you have done is the correct solution to this problem.
It's surprising that the CMake scripts in the vtkLocal example
are missing these important lines of code.  Especially since
this problem was fixed for vtkCommonPython.pyd etc. around
five years ago, but I guess it wasn't fixed for vtkLocal.

 - David


On Mon, Apr 2, 2012 at 11:55 AM, Daniël Lacko <lacko.daniel at gmail.com> wrote:
> 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.



More information about the vtkusers mailing list