Building Your Extension with distutilsΒΆ


This should not be used for new projects as it will not be supported by SIP v5.

To build the example in A Simple C++ Example using distutils, it is sufficient to create a standard, listing word.sip among the files to build, and hook-up SIP into distutils:

from distutils.core import setup, Extension
import sipdistutils

  name = 'word',
  versione = '1.0',
    Extension("word", ["word.sip", "word.cpp"]),

  cmdclass = {'build_ext': sipdistutils.build_ext}

As we can see, the above is a normal distutils setup script, with just a special line which is needed so that SIP can see and process word.sip. Then, running build will build our extension module.

If you want to use any of sip’s command-line options described in The SIP Command Line, there is a new option available for the build_ext command in distutils: --sip-opts. So you can either invoke distutils as follows:

$ python build_ext --sip-opts="-e -g" build

or you can leverage distutils’ config file support by creating a setup.cfg file in the supported system or local paths (eg: in the same directory of with these contents:

sip-opts = -e -g

and then run build as usual.

If sip-opts has not been specified then any swig_opts defined when creating the Extension will be used.