I have a header-only C++ library that I use in my Python extensions. I would like to be able to install them to Python's include path, such that I can compile extensions very easily with python3 setup.py build
. I'm partly able, but there are two things that I cannot get working (see below):
How can I use
python3 setup.py install
to install the header files? Currently I only get some*.egg
file, but not the headers installed.How can I retain the module's file structure? Currently the file structure is erroneously flattened.
What works
With the following setup.py
from setuptools import setup
setup(
name = 'so',
description = 'Example',
headers = [
'so.h',
],
)
I can upload the module to PyPi:
python3 setup.py bdist_wheel --universal
twine upload dist/*
and then install it using pip:
pip3 install so
On my system then I then find the header here
/usr/local/include/python3.6m/so/so.h
which is available when I compile the extensions with Python.
How can I use 'python3 setup.py install'?
Using this strategy I cannot simply run
python3 setup.py install
In that case some so*.egg
is installed, but the headers are not stored somewhere where they are available to the compiler.
How to retain a file structure?
When the module is a bit more complicated, and there is some directory hierarchy I also run to problems. For the following setup.py
from setuptools import setup
setup(
name = 'so',
description = 'Example',
headers = [
'so.h',
'so/implementation.h',
],
)
The problem is that the headers are installed to
/usr/local/include/python3.6m/so/so.h
/usr/local/include/python3.6m/so/implementation.h
thus flattening the original file structure.
How can I fix both issues?