O'Reilly logo

Python: Essential Reference, Third Edition by David Beazley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required