use*_*549 5 python macos numpy
从enthought安装的树冠.在构建我的.pyx文件时,我收到此错误(后面跟着更多)
我是否需要easy_install其他软件包才能获得"开发"版本,因此我得到了 .h文件?
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
Run Code Online (Sandbox Code Playgroud)
这在几个Linux安装下编译和运行,但不适用于我最近安装的Canopy发行版python
这是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
)
Run Code Online (Sandbox Code Playgroud)
这是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
Run Code Online (Sandbox Code Playgroud)
以下是python和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
Run Code Online (Sandbox Code Playgroud)
在MacBook Pro Mac OS X版本10.7.5上运行
小智 5
这是一个相当古老的问题,但这是一个经常出现的问题,其他答案非常糟糕.硬连线numpy的include目录完全打破了虚拟环境,并且会使包很难自动分发和安装.解决此问题的正确方法是使用numpy.get_include()获取与当前加载的numpy版本关联的目录.这显示在此回答类似的问题.该setup.py会是这样:
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
)
Run Code Online (Sandbox Code Playgroud)
小智 1
您可以在 setup.py 中使用以下参数告诉编译器包含头文件所在的目录:
ext_modules = [Extension("tsBinner",["tsBinner.pyx"],
include_dirs = ["/full/path/python2.7/site-packages/numpy/core/include/"])];
Run Code Online (Sandbox Code Playgroud)