Skip to Content
Python: Essential Reference, Third Edition
book

Python: Essential Reference, Third Edition

by David Beazley
February 2006
Intermediate to advanced content levelIntermediate to advanced
648 pages
14h 53m
English
Sams
Content preview from Python: Essential Reference, Third Edition

Compilation of Extensions

Extension modules are usually compiled into shared libraries or DLLs that can be dynamically loaded by the interpreter. The low-level details of this process vary on every machine, but the distutils module in the Python library can be used to simplify the process. To create an extension module using distutils, follow these steps:

1.
Create a file called setup.py that starts with the following code:
# setup.py
from distutils.core import setup, Extension
2.
Next, add some source information about your extension, as follows:
setup(name="spam", version="1.0",
      ext_modules=[Extension("spam", ["spam.c", "spamwrapper.c"])])
3.
Now, to build your extension, type the following:
python setup.py build

At this point, a shared ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python: Essential Reference

Python: Essential Reference

David M. Beazley

Publisher Resources

ISBN: 0672328623Purchase book