[Numpy-discussion] How do I ensure numpy headers are present in setup.py?

Erik Tollerud erik.tollerud@gmail....
Fri Apr 2 14:03:44 CDT 2010


I am writing a setup.py file for a package that will use cython with
numpy integration.  This of course requires the numpy header files,
which I am including by using numpy.get_includes in the setup.py file
below.  The problem is for users that have not installed numpy before
installing this package.    If they have setuptools installed, the
behavior I would want would be for numpy to be downloaded and then the
setup script should be able to get at the headers even if it doesn't
install numpy until after this package is installed.  But that doesn't
work - I have to import numpy in the setup script, which fails if it
is not yet installed.  So How can I get the behavior I want?


setup.py
------------
from distribute_setup import use_setuptools
use_setuptools()

from setuptools import setup
from setuptools.extension import Extension
from Cython.Distutils import build_ext
from numpy import get_include as numpy_includes

ext_modules = [Extension("myext",
["core.pyx","somecfile.c"],include_dirs=[numpy_includes()])]

setup(
  name = 'ext name',
  cmdclass = {'build_ext': build_ext},
  ext_modules = ext_modules,
  setup_requires=['numpy'],
  install_requires=['numpy'],
)


More information about the NumPy-Discussion mailing list