Extensions on Linux: import without underscore?

Robert Kern rkern at ucsd.edu
Sun Jun 19 07:21:27 CEST 2005

James Carroll wrote:
> Thanks Robert.
>>Call it bright.so .
> If I rename it bright.so, then I get the error:
>   ImportError: dynamic module does not define init function (initbright)

Sorry, I should have been clearer. Just renaming the file won't help. 
The init function also needs to be appropriately named.

> I'm using swig with the module declaration
>   %module bright
> I've looked at some other source, and it looks like there are some
> good reasons to have a bright.py that passes calls on to _bright.

Reread the SWIG documentation. If it is going to prepend an underscore 
to the extension name, it is usually also generating the appropriate 
bright.py . I suspect that this is why it "worked" on Windows but didn't 
work when you moved to Linux.

>>If at all possible, you should use distutils to build Python extensions.
>  Where can I find similar distutils C++ examples?  Can it do most of
> what Scons does?

Even better, it will handle running SWIG, too. wxPython itself is an 
example, and one that you most certainly should emulate.

>>If you must use Scons, read
>>   http://www.scons.org/cgi-bin/wiki/PythonExtensions
> Very nice, strange that didn't show up for all my googles of scons
> python, etc.  I like how it uses distutils to get flags...  I'm
> extending wxPython, so I'm using the wxWidgets 
> env.ParseConfig('wx-config --cppflags --libs')   Technique... I'll
> have to ponder using one or the other or both.  Hmm....

If you're extending wxPython, cannibalize wxPython's build procedure. 
Any other way, there madness lies.

Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter

More information about the Python-list mailing list