[vtkusers] Problem with Python and VTK

Prabhu Ramachandran prabhu at aero.iitm.ernet.in
Fri Apr 4 03:07:49 EST 2003


>>>>> "RM" == Richard Muller <rpm at wag.caltech.edu> writes:

    RM> I'm having trouble with making Python and VTK work nicely
    RM> together. I'm using Python 2.2.1 and VTK 4.2.1 on a Linux box.

[snip]

    RM> First, I can't use vtkpython because for some reason it
    RM> doesn't pick up the other modules in my site-packages
    RM> directory (most notably NumPy).

A traceback of this would help.  The following information would also
help:

 python -c "import sys; print sys.path"

    RM> Secondly, when I either try to rebuild with CMAKE_SKIP_RPATH
    RM> or when I delete the *.so files in the bin directory, then
    RM> Python can't find the *.so files at all. I've run the 'python
    RM> setup.py install' commands, and the libraries are under my
    RM> site-packages directory, but Python insists upon using the
    RM> version of vtk.py that is in my build directory. It's like it
    RM> remembers it somehow, although I've used 'printenv' to see if
    RM> any env variables are pointing to it, and I can't find any.

Well, the way I build and use VTK (on personal machines) is to not
install it but run it off the CVS tree (i.e. I use approach 2 as
documented in the README.txt).  It works reliably well.

If you want to use python setup.py install there are three issues that
you have to cover for.

 1. make install as provided with VTK typically installs the libs into
 /usr/local/lib/vtk which is *NOT* in your linkers path which means
 that you need to edit ld.so.conf suitably or define LD_LIBRARY_PATH.
 Admittedly this is not documented but I thought the traceback would
 help figure this one out.

 2. You need to make sure there are links to the libvtk*Python.so
 files inside site-packages/vtk_python/

 3. Finally the libvtk*.so files in your build tree need to be moved
 out of the place they were built in.

The basic idea is simple.  

 1. You need to install the VTK libs (all of them) in the linkers
 path.

 2. You need to tell Python where to find the libvtk*Python.so's and
 also where to find the directory that contains all the Python modules
 (typically Wrapping/Python)

On lab machines I install libvtk*.so into /usr/local/lib (and put this
path in ld.so.conf).  Then do the following:

 cd $VTK_SRC_ROOT/Wrapping/Python
 python setup.py install --prefix=/usr/local
 cd /usr/local/lib/python2.2/site-packages/vtk_python/
 ln -s ../../../libvtk*Python.so .

Finally I do this:

 cd $VTK_SRC_ROOT
 mv bin bin1 # or rm -rf bin


cheers,
prabhu



More information about the vtkusers mailing list