April 2016
Beginner
156 pages
3h 23m
English
Once we have written the functions successfully, the next thing to do is build the module and use it in our Python modules. The setup.py file looks like the following code snippet:
from distutils.core import setup, Extension
import numpy
# define the extension module
demo_module = Extension('numpy_api_demo', sources=['numpy_api.c'],
include_dirs=[numpy.get_include()])
# run the setup
setup(ext_modules=[demo_module])
As we are using NumPy-specific headers, we need to have the numpy.get_include function in the include_dirs variable. To run this setup file, we will use a familiar command:
python setup.py build_ext -inplace
The preceding command will create a numpy_api_demo.pyd file in the directory for us ...