How to use setup.py to compile a C extension rather than to install it

Gerhard Häring gerhard.haering at opus-gmbh.net
Mon Feb 17 13:08:35 CET 2003


Xiao-Qin Xia <xx758 at cam.ac.uk> wrote:
> Hi, there,
> 
> I am trying to write a C extension for my python scripts, to use distutils 
> offered by Python to write a setup.py is quite convient, however it seems 
> the setup.py alway installs the C extension to site-package, while I want 
> keep the c extension in the same original directory with my python scripts. 
> Anybody can tell me how to do this?

Are you doing 'install' rather than 'build'? Try this instead:

$ python setup.py build

this will build the C extension in a directory buid/lib-$platform$pythonversion

For testing, I either have a shell open in that directory or add it to
sys.path.

If you want the extension to be built in the same directory as setup.py, use:

$ python setup.py build --build-lib=.

But I don't like that, as it clutters up my source directory.

HTH,
-- 
Gerhard Häring
OPUS GmbH München
Tel.: +49 89 - 889 49 7 - 32
http://www.opus-gmbh.net/




More information about the Python-list mailing list