Extensions on Linux: import without underscore?

Robert Kern rkern at ucsd.edu
Sun Jun 19 05:57:25 CEST 2005


James Carroll wrote:
> Hi, I'm creating an extension called _bright.so on linux.  I can
> import it with import _bright, but how can I import bright and get the
> package?
> 
> On windows, I've been able to import bright instead of import _bright,

That has to be a bug. You shouldn't rely on that behavior.

> but on Linux it seems to need the underscore.  I'm tempted to create a
> bright.py with from _bright import *, but I'm wondering if there's a
> more direct way.

Call it bright.so .

> Also, I'm using scons to generate my lib, and it insists on prepending
> the characters lib to my library name, so if I tell it to generate
> _bright.so it gives me lib_bright.so.  Is there a way of turning this
> off so I don't have to rename it back to _bright.so?

If at all possible, you should use distutils to build Python extensions.

If you must use Scons, read

   http://www.scons.org/cgi-bin/wiki/PythonExtensions

and use

SharedLibrary(...
               SHLIBPREFIX="",
               ...)

-- 
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