[CMake] problems with VTK python module installation on OSX (after a custom build)

Martin Costabel costabel at wanadoo.fr
Wed Sep 3 04:02:31 EDT 2008


Darren Weber wrote:
[]
> ImportError: 
> dlopen(/usr/local/lib/python2.5/site-packages/vtk/libvtkCommonPython.so, 
> 10): Library not loaded: libvtkCommonPythonD.5.2.dylib
>   Referenced from: 
> /usr/local/lib/python2.5/site-packages/vtk/libvtkCommonPython.so
>   Reason: image not found

This is not a problem you can solve with PYTHONPATH. It is not python 
that is trying to find the dylib, but dlopen(). And dlopen does not look 
at PYTHONPATH.

There are several different ways how you can solve this problem (as 
always on Mac OSX, given its hybrid Unix/NextStep nature):

The simplest and cleanest way (this is how it is done by the Fink VTK 
package, for example, perhaps also by macports vtk5) is to build vtk in 
such a way that its dylibs have decent install_names that correspond to 
the place where they are installed. In this way, dlopen() finds the 
dylib without any help, because the full path name (or a correct 
relative path name) of the dylib is hardcoded inside the 
libvtkCommonPython.so python module. For example, I get from the command

otool -L /sw/lib/python2.5/site-packages/vtk/libvtkCommonPython.so |head -n3

the output:

/sw/lib/python2.5/site-packages/vtk/libvtkCommonPython.so:
	/sw/lib/vtk/libvtkCommonPythonD.5.0.dylib (compatibility version 5.0.0, 
current version 5.0.4)
	/sw/lib/vtk/libvtkCommon.5.0.dylib (compatibility version 5.0.0, 
current version 5.0.4)

You see the whole path of libvtkCommonPythonD.5.0.dylib there. I am sure 
in your case, you will see only "libvtkCommonPythonD.5.0.dylib", without 
its path. This is the default when building VTK. If you want to get the 
correct install_name, you have to build VTK (this is for 5.0, I haven't 
tried 5.2 yet) with the cmake parameters


   -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON \
   -DVTK_USE_RPATH=ON

Another way to help dlopen, if your VTK is built without install_names 
for its dylibs, is to use one of the environment variables 
LD_LIBRARY_PATH, DYLD_FALLBACK_LIBRARY_PATH or DYLD_LIBRARY_PATH (do 
*not* use the latter, it risks wreaking havoc on your system). See "man 
dlopen".

-- 
Martin




More information about the CMake mailing list