无法使用distutils构建Cython模块

时间:2017-07-28 11:07:42

标签: python c python-2.7 cython distutils

我正在尝试构建Cython以尝试通过尝试将cython与C头链接来从python调用C函数。 当我尝试使用此命令来构建python

python setup.py build_ext --inplace

它显示此错误:

running build_ext
building 'cython' extension
/usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c cython.c -o build/temp.macosx-10.6-intel-2.7/cython.o
cython.c:692:14: error: typedef redefinition with different types ('void' vs
      'struct _typeobject')
typedef void PyTypeObject;
             ^
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/object.h:411:3: note: 
      previous definition is here
} PyTypeObject;
  ^
1 error generated.
error: command '/usr/bin/clang' failed with exit status 1

编辑:我的cython.pyx看起来像这样:

cdef extern from "rnafoldenergy.h":
    float dostuff(int maxw, char *sequence2, char *sequence3, float *freeenergy)



cpdef int dothings():
    print "Hello!"

    cdef int maxw = 50

    cdef float freeenergyarray[3]
    freeenergyarray[:] = [0, 0, 0]
    cdef char* sequence2 = "AAACATTGAAAATAAGAGTACATGAAGGATATGAGGAATTCACAATGGTTGGGCGAAGAGCAACAGCCATTCTAAGGAAAGCAACCAGAAGACTGATCCAACTGATAGTGAGTGGGAAAG"
    cdef char* sequence3 = "ATCCTTCATGTACTCTTATTTTCAATGTTTATAAAAGAGGAGAAATATAAAATGTGAAAATAAAACCTGGCGGCAGCGCAAAAG"

    cdef float interactenergy=0


    interactenergy=dostuff(maxw=maxw, sequence2=sequence2, sequence3=sequence3, freeenergy=freeenergyarray)


    print "A: %f, B: %f, AB: %f, Interact: %f" % (freeenergyarray[0],freeenergyarray[1],freeenergyarray[2],interactenergy)

    return 0

1 个答案:

答案 0 :(得分:2)

我认为这是因为你正在调用你的文件“cython.pyx”。我可以使用名为“cython.pyx”的文件重现您的错误,但是如果我将其重命名为其他内容,那么我就不会得到行typedef void PyTypeObject;,因此不会收到错误。

为什么这会产生确切的错误,这有点神秘,但鉴于已经有一个名为“cython”的模块(你正在使用......),最好不要将你的模块称为同一个东西。