Skip to Content
NumPy Essentials
book

NumPy Essentials

by Jaidev Deshpande, Leo (Liang-Huan) Chin, Tanmay Dutta, Shane Holloway
April 2016
Beginner content levelBeginner
156 pages
3h 23m
English
Packt Publishing
Content preview from NumPy Essentials

Building and installing the extension module

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

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

SciPy and NumPy

SciPy and NumPy

Eli Bressert
Python Distilled

Python Distilled

David M. Beazley

Publisher Resources

ISBN: 9781784393670Supplemental Content