Antonis Christofides
Antonis Christofides

Reputation: 6949

`python -m build` can't find numpy include files when running in cibuildwheel

I'm building a python module that contains a cython file which uses numpy. In some environments python -m build works as is; in other environments I need to set C_INCLUDE_PATH=`python -c "import numpy; print(numpy.get_include())"` beforehand.

But when I type cibuildwheel, I always get fatal error: numpy/arrayobject.h: No such file or directory. I can't figure out how I can help it find these files.

Upvotes: 0

Views: 41

Answers (1)

Antonis Christofides
Antonis Christofides

Reputation: 6949

I was using this in pyproject.toml:

[tools.setuptools]
ext-modules = [
    {name = "haggregate.regularize", sources = ["src/haggregate/regularize.pyx"]}
]

The problem is that include_dirs is not accepted there, and even if it were accepted, it couldn't be dynamic. Besides, setuptools warns that tools.setuptools.ext-modules is experimental. Therefore I removed that part from pyproject.toml and added this setup.py, which works without problem.

import numpy
from Cython.Build import cythonize
from setuptools import Extension, setup

setup(
    ext_modules=cythonize(
        Extension(
            "haggregate.regularize",
            sources=["src/haggregate/regularize.pyx"],
            include_dirs=[numpy.get_include()],
        )
    ),
)

In other words, I was trying too hard to avoid using the deprecated setup.py, but it seems it's not entirely deprecated yet, and that it's OK to use it minimally pending further maturation of pyproject.toml and setuptools.

Upvotes: 0

Related Questions