Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify header files in setup.py script for Python extension module?

Tags:

How do I specify the header files in a setup.py script for a Python extension module? Listing them with source files as follows does not work. But I can not figure out where else to list them.

from distutils.core import setup, Extension from glob import glob  setup(     name = "Foo",     version = "0.1.0",     ext_modules = [Extension('Foo', glob('Foo/*.cpp') + glob('Foo/*.h'))] ) 
like image 467
Johan Råde Avatar asked Jul 09 '11 08:07

Johan Råde


People also ask

What should setup py contain?

The setup.py file may be the most significant file that should be placed at the root of the Python project directory. It primarily serves two purposes: It includes choices and metadata about the program, such as the package name, version, author, license, minimal dependencies, entry points, data files, and so on.

What is PIP Setuptools?

setuptools.readthedocs.io , PyPI page. Setuptools is a package development process library designed to facilitate packaging Python projects by enhancing the Python standard library distutils (distribution utilities).

What is distutils Python?

Distutils is a mechanism to distribute Python packages and extensions provided in the Python standard library since Python 1.6.


2 Answers

Add MANIFEST.in file besides setup.py with following contents:

graft relative/path/to/directory/of/your/headers/ 
like image 176
iElectric Avatar answered Oct 24 '22 08:10

iElectric


Try the headers kwarg to setup(). I don't know that it's documented anywhere, but it works.

setup(name='mypkg', ..., headers=['src/includes/header.h']) 
like image 39
Tycho Andersen Avatar answered Oct 24 '22 08:10

Tycho Andersen