[vtkusers] ImportError with VTK 4.x, Python 2.2, BCC32 5.5 [SOLVED]

Charl P. Botha c.p.botha at its.tudelft.nl
Fri Sep 13 21:33:36 EDT 2002

On Sat, Sep 14, 2002 at 12:45:26AM +0200, Charl P. Botha wrote:
> I'm trying to get VTK 4.x (CVS checkout) going on Windows as well.  After
> having built VTK with the downloadable Borland compiler version 5.5, I get
> the following when trying to run the Cone.py example:
> C:\Build\VTK\Examples\Tutorial\Step1\Python> \Python22\python Cone.py
> Traceback (most recent call last):
>   File "Cone.py", line 9, in ?
>     from vtkpython import *
>   File "c:\Build\VTK\Wrapping\Python\vtkpython.py", line 7, in ?
>     from vtk import *
>   File "c:\Build\VTK\Wrapping\Python\__init__.py", line 7, in ?
>     from common import *
>   File "c:\Build\VTK\Wrapping\Python\vtk\common.py", line 9, in ?
>     from vtkCommonPython import *
> ImportError: dynamic module does not define init function
> (initvtkCommonPython)
> The PYTHONPATH points to both c:\Build\VTK\bin (where
> vtkCommonPython.{lib,dll,tds} live) and c:\Build\VTK\Wrapping\Python and my
> PATH points to c:\Build\VTK\bin as well.  From the message (and from
> experiments) it does seem that Python is finding the vtkCommonPython.dll,
> but that it's not happy with it.

The problem is the following: I am using a binary Python installation from
http://www.python.org/ and this is presumably built with MSVC.  BCC32, by
convention, prepends a leading underscore to all exported functions, so
"initvtkCommonPython" becomes "_initvtkCommonPython" during the VTK build.
Python expects the former and so can not find this function in the DLL.
This is true for all the other kits (Rendering, Filtering, Graphics, etc.)
as well.

The solution is to create Borland module definition files for all kits in
the VTK binary (output) directory, in my case VTK/bin.  Each .def file must
have the same basename as the DLL, e.g. vtkCommonPython.def and must be
present at VTK link time.  The def file contains an export alias, e.g.:

Seeing that it took me quite a while to figure this out, could we perhaps
add it to a FAQ somewhere?  I could also checkin a README.Python-W32 file in
the VTK/Wrapping/Python directory.


charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/

More information about the vtkusers mailing list