关键在于 import_array(),否则必然崩溃。
#include <Python.h> #include <numpy/arrayobject.h> //必须这样写! void init_numpy() { import_array(); } int fext_python_init(const char* pPath) { PyObject *pArgs = NULL; Py_Initialize(); init_numpy(); PyObject* pArgs = PyTuple_New(1); //将c的img数组数据转换成pyobject类型的数组数据 npy_intp dims[1] = {pImage->clip.width * pImage->clip.height * 4}; //给定维度信息 PyObject *pPyArray = PyArray_SimpleNewFromData(1, dims, NPY_CHAR, pImage->buffer.data); PyTuple_SetItem(pArgs, 1, pPyArray); …… }