无法使用 distutils 构建 Cython 模块
Failure to build Cython module using distutils
我正在尝试通过尝试 link cython 和 C headers 来构建 Cython 以尝试从 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
我想这是因为你调用了你的文件 "cython.pyx"。我可以使用名为 "cython.pyx" 的文件重现您的错误,但如果我将其重命名为其他名称,则我不会收到 typedef void PyTypeObject;
行,因此不会收到错误。
为什么这会产生那个确切的错误有点神秘,但鉴于已经有一个名为 "cython" 的模块(您正在使用...),最好不要调用您的模块同样的事情。
我正在尝试通过尝试 link cython 和 C headers 来构建 Cython 以尝试从 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
我想这是因为你调用了你的文件 "cython.pyx"。我可以使用名为 "cython.pyx" 的文件重现您的错误,但如果我将其重命名为其他名称,则我不会收到 typedef void PyTypeObject;
行,因此不会收到错误。
为什么这会产生那个确切的错误有点神秘,但鉴于已经有一个名为 "cython" 的模块(您正在使用...),最好不要调用您的模块同样的事情。