简体   繁体   English

编译.pyx文件时缺少numpy / arrayobject.h

[英]Missing numpy/arrayobject.h while compiling .pyx file

Installed canopy from enthought. 从enthought安装的树冠。 While building my .pyx file, I get this error (followed by more) 在构建我的.pyx文件时,我收到此错误(后跟更多)

Do I need to easy_install additional packages to get the "development" version so I get the .h files? 我是否需要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

More Context 更多背景

This compiles and runs under several Linux installations, but does not work with my recently-installed Canopy distribution python 这在几个Linux安装下编译和运行,但不适用于我最近安装的Canopy发行版python

here is the content of setup.py 这是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 这是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 以下是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 

Running on a MacBook Pro Mac OS X Version 10.7.5 在MacBook Pro Mac OS X版本10.7.5上运行

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. 硬连线numpy的include目录完全打破了虚拟环境,并且会使包很难自动分发和安装。 The correct way to solve this is using numpy.get_include() to obtain the directory associated with the currently loaded numpy version. 解决此问题的正确方法是使用numpy.get_include()来获取与当前加载的numpy版本关联的目录。 This is shown in this answer to a similar problem. 这显示在回答类似的问题。 The setup.py would be like this: 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
)

You can tell the compiler to include the directory where your header files reside using the following parameter in your setup.py: 您可以使用setup.py中的以下参数告诉编译器包含头文件所在的目录:

ext_modules = [Extension("tsBinner",["tsBinner.pyx"],
              include_dirs = ["/full/path/python2.7/site-packages/numpy/core/include/"])];

This is a problem found in all Canopy distributions. 这是所有Canopy发行版中都存在的问题。 The answer below is for a Mac. 以下答案适用于Mac。 It should be fairly obvious what to do in Linux and Windows; 在Linux和Windows中应该做的很明显: the folders are just slightly different. 文件夹略有不同。


After making the .c file, the setup.py file automatically runs the following for you 制作.c文件后,setup.py文件会自动为您运行以下命令

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 MyCythonCode.c -o build/temp.macosx-10.6-x86_64-2.7/MyCythonCode.o

Then you get the errors about the missing .h files: arrayobject.h and ufuncobject.h 然后你得到关于丢失的.h文件的错误: arrayobject.hufuncobject.h

Looking at the code above, in particular the -I option, the problem lies in that gcc is looking for these files in: 查看上面的代码,特别是-I选项,问题在于gcc正在寻找这些文件:

/Applications/Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/include/python2.7

Type the following into a terminal window, to find where these files are: 在终端窗口中键入以下内容,以查找这些文件的位置:

find /Applications/ -name "ufuncobject.h"

For the Canopy installation on my Mac, they appeared in a couple of place. 对于Mac上的Canopy安装,它们出现在几个地方。 The location I'm interested in is the folder of the latest Canopy update (1.1.0.1371 for me). 我感兴趣的位置是最新的Canopy更新文件夹(对我来说是1.1.0.1371)。 So the files ere located, for me, here: 所以这些文件在我这里找到了:

/Applications//Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/lib/python2.7/site-packages/numpy/core/include/numpy/ufuncobject.h

Note that the error messages ask for two files within a folder called numpy . 请注意,错误消息要求在名为numpy的文件夹中包含两个文件。 If you just copy the two files in question, then you'll hit more errors. 如果您只是复制有问题的两个文件,那么您将遇到更多错误。 Copy the whole of the numpy folder, in this case the folder located in (one folder up from before): 复制整个numpy文件夹,在这种情况下是位于(之前的一个文件夹)中的文件夹:

/Applications//Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/lib/python2.7/site-packages/numpy/core/include/

Paste this folder into the folder the compiler is looking in (ie the one listed as the -I option above). 将此文件夹粘贴到编译器正在查找的文件夹中(即上面列为-I选项的文件夹)。 In my case, this is: 就我而言,这是:

/Applications//Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/lib/python2.7/

Now try running the setup file again. 现在尝试再次运行安装文件。 It should be okay. 应该没问题。

I have always found this to be an issue with Enthought distributions. 我一直认为这是Enthought发行版的一个问题。 As great as EPD was and Canopy is, it's a real pain that this has to be manually fixed each time. 就像EPD和Canopy一样伟大,每次都必须手动修复这是一个真正的痛苦。

Hope this helps. 希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误:numpy/arrayobject.h:google colab 中没有这样的文件或目录#include“numpy/arrayobject.h” - fatal error: numpy/arrayobject.h: No such file or directory #include "numpy/arrayobject.h" in google colab 在Windows中编译SWIG python包装程序时,MinGW g ++找不到numpy \\ arrayobject.h - numpy\arrayobject.h not find by MinGW g++ while compiling SWIG python wrapper in Windows 在编译swig输出时找不到arrayobject.h - arrayobject.h not found while compiling swig output Cython:“致命错误:numpy/arrayobject.h:没有这样的文件或目录” - Cython: "fatal error: numpy/arrayobject.h: No such file or directory" cimport给出致命错误:找不到“ numpy / arrayobject.h”文件 - cimport gives fatal error: 'numpy/arrayobject.h' file not found 致命错误:numpy / arrayobject.h:没有这样的文件或目录 - fatal error: numpy/arrayobject.h: No such file or directory Cython:致命错误:未找到“numpy/arrayobject.h”文件,使用 numpy - Cython: fatal error: 'numpy/arrayobject.h' file not found, using numpy 如何解决这个致命错误:numpy/arrayobject.h:没有这样的文件或目录? - How do I resolve this make fatal error: numpy/arrayobject.h: No such file or directory? 相当于使用#include <Numeric/arrayobject.h> 在Numpy - equivalent of using #include <Numeric/arrayobject.h> in Numpy 致命错误:使用 pyenv 时找不到“arrayobject.h”文件 - fatal error: 'arrayobject.h' file not found when using pyenv
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM