我有一个非常简单的cython
代码,它是用python3
构建的
python3 setup.py build_ext
cpdef public int say_hello ():
print("HELLO")
return 1
我在C
程序中调用的
#include <Python.h>
Py_Initialize();
PyInit_libwrapper();
int ok = say_hello();
这是我得到的错误
#0 0x00007fffeabebb52 in PyTuple_Pack () at /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
#1 0x00007fffea7eb8f1 in __Pyx_PrintOne (stream=0x0, o=<optimized out>) at code/cython/wrapper.c:2123
#2 0x00007fffea7eb8f1 in say_hello (__pyx_skip_dispatch=<optimized out>) at code/cython/wrapper.c:1114
如果我不调用print
函数,一切都会很好,而且如果我使用python2
(如下),一切都会很好
python2 setup.py build_ext
#include <python2.7/Python.h>
Py_Initialize();
initlibwrapper();
int ok = say_hello();
哪里出问题了?
编辑:
添加评论
#cython: language_level=3
我遇到了另一个错误
say_hello (__pyx_skip_dispatch=0) at code/cython/wrapper.c:1106
1106 __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 21, __pyx_L1_error)
(gdb) bt
#0 0x00007fffea7eb8cc in say_hello (__pyx_skip_dispatch=0) at code/cython/wrapper.c:1106