[Distutils] Swig support

Tessa Lau tlau at tlau.org
Tue Feb 7 05:39:21 CET 2006


Hi,

I'm using distutils with python 2.4.2 on Linux and trying to distribute 
a complex package including an extension module.  I'm using SWIG to wrap 
the extension module.

If I invoke swig normally from the command line with "swig -python 
notes.i", then swig generates a "notes.py" wrapper as well as a 
"notes_wrap.c" source code file.  It expects this source file to be 
compiled into a module named "_notesmodule.so" (on Linux).

I tried recreating the same functionality with distutils, using the 
following setup.py code:

    ext_modules = [Extension('mypkg.notes', ['wrapper/notes.i'],
        include_dirs=['include'],
        swig_opts=['-Iinclude'])]

What happens is that distutils converts "notes.i" into "notes.so" (which 
cannot be imported as a module) and fails to install the generated 
"notes.py" wrapper script, which is also required for the module to work.

The "notes.so" built by distutils cannot be imported by python because 
the swig-generated C source code declares the module name to be 
"_notes", and this doesn't correspond to the name of the created shared 
library.  This is similar to the shadow class behavior found in earlier 
releases of swig, but now it's the default behavior.

Is this supposed to work?  Am I doing something wrong, or is SWIG 
support just broken in this release?

Thanks,
--Tessa


More information about the Distutils-SIG mailing list