Cython无法转换为int?

时间:2015-05-13 09:31:05

标签: python cython

使用Anaconda,Python 3.4和Win7 64bit,我无法运行:

C代码:

    int addInts(int a, int b)
{
    return a+b;
}

PYX文件:

cdef extern from "square.cpp":
    int addInts(int, int)

def pAddInts(int a, int b):
    return addInts(a, b)

和testfile:

res = callCpp.pAddInts(3, 4)

错误消息:

Traceback (most recent call last):
  File "testScript.py", line 9, in <module>
    res = callCpp.pAddInts(a, b)
  File "callCpp.pyx", line 16, in callCpp.pAddInts (callCpp.cpp:952)
    def pAddInts(int a, int b):
TypeError: __int__ returned non-int (type int)

没有问题@all with double和double *,但是int不起作用.. 问题出在这里?谢谢!

1 个答案:

答案 0 :(得分:0)

好的解决方案: mingw不适合这项工作,它必须是Microsoft VC ++。这有助于完美: https://github.com/cython/cython/wiki/InstallingOnWindows