6

思いつきでキャノピーを取り付けました。ファイルのビルド中.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

より多くのコンテキスト

これは、いくつかの 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 
)

ここに 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

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 

MacBook Pro Mac OS X バージョン 10.7.5 での実行

4

3 に答える 3

5

これはかなり古い質問ですが、よくある問題であり、他の回答は非常に悪いです。numpy のインクルード ディレクトリをハードワイヤリングすると、仮想環境が完全に壊れ、パッケージの配布と自動インストールが非常に難しくなります。これを解決する正しい方法は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
)
于 2016-03-03T22:19:55.323 に答える
1

setup.py で次のパラメーターを使用して、ヘッダー ファイルが存在するディレクトリを含めるようにコンパイラに指示できます。

ext_modules = [Extension("tsBinner",["tsBinner.pyx"],
              include_dirs = ["/full/path/python2.7/site-packages/numpy/core/include/"])];
于 2013-10-02T16:02:41.283 に答える