Instructions for building VTK with PYTHON
David Gobbi, dgobbi@irus.rri.on.ca
v0.7-pre, 25 Oct 1999

This document briefly describes how to build and install the python
interface to VTK under UNIX and Windows

Revision History:
v0.6  11 Oct  1999  Added Table of Contents, minor adjustments 
v0.5  20 July 1999  First version

Table Contents:

1) Building and installing vtk with python under Windows 95/98/NT	
  1.1) The binary distribution of VTK
  1.2) Building vtk under Windows from source distribution of VTK
    1.2.2) If you build python yourself from source code
    1.2.3) If you installed the standard binary distribution of python
  1.3) Installing the VTK python wrappers

2) Building and installing vtk with python under unix
  2.1) Building the python components of VTK
    2.1.1) Editing user.make (refer to Section 3.3.3 of the HOWTO)
    2.1.2) Configure vtk
    2.1.3) Build VTK
  2.2) Install VTK
  2.3) Using VTK through python




1) Building and installing vtk with python under Windows 95/98/NT
-----------------------------------------

1.1) The binary distribution of VTK

Please note that the binary distribution of VTK for windows already
includes a python interface, in the installer vtk24python.exe, as of 
vtk2.4.  Any python files you put in the vtk24\python directory can 
use the interface.  An example file, Cone.py, is included. 

1.2) Building vtk under Windows from source distribution of VTK

You should thoroughly familiarize yourself with the instructions
on building vtk on windows given by Sebastian Barre at 
http://www.hds.utc.fr/~barre/vtk/vtk-tcltk8-win.html

If you want to use a debugger with vtk-python, you must build a
debug version of python from source.  If you do not want
to use a debugger, you can use the standard binary python 
distribution from http://www.python.org/.


1.2.2) If you build python yourself from source code

Run the pcmaker.exe executable as described on the Sebastian's
VTK-Windows web page, check the 'Build Python' box, and enter the 
path to the python source directory.
Ensure that the 'Build Lean VTK' box is _not_ checked.

Use the DOS shell to go to the vtkbin directory, and type 'nmake'
as described on Sebastian's page.  You might have to edit 
vtkbin/vtkpython/Makefile to specify where the Python include
files are.

Note that Python 1.5.2 will not run properly with Tcl/Tk 8.1 or
Tcl/Tk 8.2.  You should use Tcl/Tk 8.0p2 through Tcl/Tk 8.0.5.

1.2.3) If you installed the standard binary distribution of python

Run the pcmaker.exe executable as described on the Sebastian's
VTK-Windows web page, check the 'Build Python' box, and enter the 
path to the python directory, i.e. "C:\Program Files\Python". 
Ensure that the 'Build Lean VTK' box is checked.

After pcmaker.exe has completed, load the file 'vtkbin/vtkpython/Makefile' 
into a text editor.  Search for the string 'PCbuild', and replace it 
with 'libs' (it only occurs once).  This specifies where the compiler 
will look for python15.lib.

Then run nmake as specified on Sebastians web page.

Note that Python 1.5.2 will not run properly with Tcl/Tk 8.1 or
Tcl/Tk 8.2.  You should use Tcl/Tk 8.0p2 through Tcl/Tk 8.0.5.


1.3) Installing the VTK python wrappers

In order to use VTK, all of the .dll files in vtkbin/lib (except
for vtkpython.dll itself) must be in the path.  You can copy the .dll's
into the \windows\system directory (\winnt\system32 on WindowsNT),
or edit the PATH system variable to specify where they are.

The vtkpython.dll file must be in the python module path.  You
should create a PYTHONPATH system variable which specifies the
path to vtkpython.dll (e.g. "C:\vtkbin\lib").  

Finally, if you want to use the vtkTkRenderWidget.dll (which comes 
with the binary distribution of VTK), you must either copy it into
the \windows\system directory (\winnt\system32 on WindowsNT) or
keep a copy in the directory where you keep your .py files. 


2) Building and installing vtk with python under unix
-----------------------------------------------------

2.1) Building the python components of VTK

A good source of information on installing VTK under UNIX
is the VTK-Linux-HOWTO, which is included with the VTK source
code and referenced at http://www.kitware.com/vtk.html.
Note that if you are building on a computer which has OpenGL
you will not have to install Mesa. 


2.1.1) editing user.make (refer to Section 3.3.3 of the HOWTO)

You will have to edit user.make to specify where the python
include files are.  On Linux, python will already be installed,
and you should specify

PYTHON_INCLUDES=-I/usr/include/python1.5       

For other UNIX, you might have to build python yourself.  Get
the source code from http://www.python.org/.  A common place
to install python is /usr/local/, in which case you specify:

PYTHON_INCLUDES=-I/usr/local/include/python1.5


2.1.2) configure vtk

In the top-level vtk directory, run the configure script:

  ./configure --with-shared --with-python --with-contrib

If you have Mesa instead of OpenGL, you will have to add 

  --with-mesa

and if you want to try out the vtkTkRenderWidget for python,
you must have tcl/tk installed on your machine and add the flag

  --with-tkwidget

When you run the configure script, ignore any warnings that say
"configure: warning: no configuration information is in python".


2.1.3) build VTK

After you have run the configure script, type

  make

If make reports that there are syntax errors, then your version
of make might not be able to install VTK.  If you are not using
Linux, download and install GNU make.

If no errors occur (it takes a -long- time for VTK to build),
the VTK libraries will be vtk/python/.


2.2) install VTK

The VTK-Linux-HOWTO provides instructions on installing VTK.
Essentially, you must either copy or link all of the libraries
(the .so files) in vtk/common, vtk/graphics, etc. into your 
library path.

The python interface is vtk/python/vtkpython.so.  It must be
somewhere in your python path.  There are two ways that you
can ensure that python finds vtkpython.so (these examples
assume that you installed vtk in /usr/local):

I) edit your .cshrc file and add the line

    setenv PYTHONPATH /usr/local/vtk/python/

-OR-

II) make a directory where you plan to keep all of your .py files.
    Use cd to get to that directory, create links from that directory
    to vtkpython.so and VTK.py:

     ln -s /usr/local/vtk/python/vtkpython.so .
     ln -s /usr/local/vtk/python/VTK.py .

The vtkTkRenderWidget for python is also in the vtk/python directory,
assuming that you configured with --with-tkwidget.  In order to use 
it, you should do one of the following:

I) edit your .cshrc file and add the line

    setenv VTK_TK_WIDGET_PATH /usr/local/vtk/python

  to specify where the vtkTkRenderWidget is located,

-OR-

II) link it into the tcl/tk package path, E.g if tcl/tk is installed in
    /usr/local then type
   
     ln -s /usr/local/vtk/python/vtkTkRenderWidget /usr/local/lib

    If tcl/tk is in /usr (i.e. on a Linux system) then use

     ln -s /usr/local/vtk/python/vtkTkRenderWidget /usr/lib


----------------------------------------------------------
2.3) Using VTK through python

The vtk-python interface provides two modules that you can 
load into python.

The first is the standard interface, contained in the file
vtkpython.so.  To load it, start python and type:

  from vtkpython import *

The second interface module, VTK.py, can only be used if
you have Tkinter installed (which comes with most python
distributions).  It is used as follows:

   from VTK import *

If you configured with --with-tkwidget, then you can create
a vtkTkRenderWidget for use with Tkinter as follows:
 
   from VTK import *

   root = Tk()
   tkWidget = vtkTkRenderWidget(root,width=200,height=200)
   renderWindow = tkWidget.GetRenderWindow()

See the Cone.py example in vtk/python.

----------------------------------------------------------
END OF FILE

