Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing numpy/arrayobject.h while compiling .pyx file

Installed canopy from enthought. While building my .pyx file, I get this error (followed by more)

Do I need to easy_install additional packages to get the "development" version so I get the .h files?

gcc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -DNDEBUG -g -O3 -arch x86_64 -I/Applications/Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/include/python2.7 -c tsBinner.c -o build/temp.macosx-10.6-x86_64-2.7/tsBinner.o
tsBinner.c:314:31: error: numpy/arrayobject.h: No such file or directory
tsBinner.c:315:31: error: numpy/ufuncobject.h: No such file or directory

More Context

This compiles and runs under several Linux installations, but does not work with my recently-installed Canopy distribution python

here is the content of setup.py

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

ext_modules = [Extension("tsBinner",["tsBinner.pyx"])]

setup(
  name ='time stamp binner',
  cmdclass = {'build_ext': build_ext},
  ext_modules = ext_modules 
)

Here is the content of tsBinner.py

from __future__ import division
import numpy as np
cimport numpy as np

#cimport cython
#@cython.boundscheck(False)
def tsBinner(np.ndarray[np.uint64_t, ndim=1] tstamps, \
    np.ndarray[np.int_t, ndim=1] bins):
    """
    bin the values of the tstamps array into the bins array.

    tstamps array is of type np.uint64

    bins array is of type int
    """
    cdef int nTStamps = tstamps.shape[0]
    cdef int iTStamp
    for iTStamp in range(nTStamps):
        bins[tstamps[iTStamp]] += 1
    return

Here are the versions of python and gcc

mac-119562:cosmic stoughto$ which python
/Users/stoughto/Library/Enthought/Canopy_64bit/User/bin/python
mac-119562:cosmic stoughto$ which gcc
/usr/bin/gcc
mac-119562:cosmic stoughto$ gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build     2336.11.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

mac-119562:cosmic stoughto$ python --version
Python 2.7.3 --  64-bit 

Running on a MacBook Pro Mac OS X Version 10.7.5

like image 700
user2824549 Avatar asked Sep 27 '13 18:09

user2824549


1 Answers

This is a fairly old question, but it is a frequent problem and the other answers are very bad. Hard-wiring numpy's include directory completely breaks virtual environments and would make the package very hard to distribute and install automatically. The correct way to solve this is using numpy.get_include() to obtain the directory associated with the currently loaded numpy version. This is shown in this answer to a similar problem. The setup.py would be like this:

import numpy
setup(
  name ='time stamp binner',
  cmdclass = {'build_ext': build_ext},
  ext_modules = ext_modules,
  include_dirs = [numpy.get_include()] #Include directory not hard-wired
)
like image 81
Dimas Abreu Dutra Avatar answered Oct 12 '22 09:10

Dimas Abreu Dutra