Compiling C++ Python Extensions

A Python Extension module is defined inside the setup.py of a Tropofy app (or any Python distribution). For example:

from setuptools import setup, find_packages
from distutils.core import Extension

requires = [
    'tropofy',
]

setup(
    name='tropofy-spanning-tree',
    version='1.0',
    description='This is a Tropofy example package',
    author='Tropofy',
    url='http://www.tropofy.com',
    packages=find_packages(),
    include_package_data=True,
    ext_modules=[Extension(
        name='exmod',
        sources=['exmodmodule.cpp']
    )],
    install_requires=requires,
)

Linux C++ Compiler

Installing a Python Extension module on a linux distribution requires the gcc compiler. By default, gcc is installed on most linux distributions. If gcc is not install, the following command can be executed,

$ sudo apt-get install build-essential

Now that gcc is installed, cd to your app directory containing setup.py and install your Tropofy app in the regular way:

$ python setup.py develop

Windows C++ Compiler

The Windows SDK includes a 64 bit compiler that can be used to compile Python Extension modules. This build environment is accessible via Start->Microsoft Windows SDK->CMD Shell.

For 32 bit machines, open the CMD Shell and locate your apps setup.py. The Python Extension module can be installed by running,

c:\> set DISTUTILS_USE_SDK=1
c:\> python setup.py install

For 64 bit machines, open the CMD Shell and locate your apps setup.py. The Python Extension module can be installed by running,

c:\> set DISTUTILS_USE_SDK=1
c:\> setenv /x64 /release
c:\> python setup.py install

Please refer to the Python setuptools documentation to learn more about the features of setuptools.