distutils for simple extension-building withPython 1.6b1

Alex Martelli alex at magenta.com
Fri Aug 25 19:27:47 EDT 2000


Thread was originally:
    updated version of David Ascher's compile.py?

To my request about updated versions of compile.py,
Thomas Heller had commented:

> > Note that nowadays the easiest way to build an extension
> > may be to write a distutils setup script,
> > and then do 'setup.py build_ext'.
> > This will automatically get it right, you can also
> > build a debug version, and there are other benefits as well.

and I had carped about the lack of docs on how to do it
(quite ungracious of me: I apologize!).

While the docs are indeed mute on the subject, there is
of course enough info in the sources to make an example
(with some experimentation).  So, I ferreted it out, and
here it is, for the benefits of others needing to build
extensions on 1.6b1 (particularly ActivePython or other
Win32 distribution; ActivePython and VC++6 is what I
have at hand).

Assuming directory promo contains a single-source C
extension called promodule.c, setup.py could be:

from distutils.core import setup, Extension

setup(name = "Promo",
    version = "0.1",
    description = "Prova Ext-build with distutils",
    author = "Alex Martelli",
    author_email = "alex at magenta.com",

    ext_modules = [Extension('pro',['promodule.c'])]
    )

Now, running, from a DOS box, in this directory:

    python setup.py build_ext

will result in:

D:\Python16\promod>python setup.py build_ext
running build_ext
building 'pro' extension
creating build
creating build\temp.win32
creating build\temp.win32\Release
D:\msdev6\VC98\BIN\cl.exe /c /nologo /Ox /MD /W3 -ID:\PYTHON16\Include
/Tcpromod
ule.c /Fobuild\temp.win32\Release\promodule.obj
promodule.c
creating build\lib.win32
D:\msdev6\VC98\BIN\link.exe /DLL /nologo /INCREMENTAL:NO
/LIBPATH:D:\PYTHON16\li
bs python16.lib /EXPORT:initpro build\temp.win32\Release\promodule.obj
/OUT:buil
d\lib.win32\pro.pyd /IMPLIB:build\temp.win32\Release\pro.lib
   Creating library build\temp.win32\Release\pro.lib and object
build\temp.win32
\Release\pro.exp

D:\Python16\promod>dir build\lib.win32

 Volume in drive D is DISCO D
 Volume Serial Number is 4140-11E0
 Directory of D:\Python16\promod\build\lib.win32

.              <DIR>        08-26-00  1:23a .
..             <DIR>        08-26-00  1:23a ..
PRO      PYD        20,480  08-26-00  1:23a pro.pyd
         1 file(s)         20,480 bytes
         2 dir(s)     336,371,712 bytes free

D:\Python16\promod>


so the .pyd file is built, and you just have to move it where it's
needed (I assume the process will be similarly simple on other
platforms).


A really nice and usable package, these distutils, it would
seem from such an early and simple test -- and of course
they'd come in even handier for more complicated cases,
since the whole architecture seems elegant & powerful.

A big round of applause to all responsible...!  & thanks.


Alex






More information about the Python-list mailing list