小编Con*_*ode的帖子

为什么 PyObject_Print 崩溃?

我一直在使用 Python 3.3 C-API,看看是否可以在计划中的即将进行的项目中使用它,但几乎立即遇到了问题。

即使是这么简单的代码也会崩溃并返回 0xc0000005:

#include <Python.h>
#include <cstdio>

int main(){
    Py_Initialize();

    Py_IncRef(Py_True); //just in case?
    PyObject_Print(Py_True,stdout,Py_PRINT_RAW);
    Py_DecRef(Py_True);

    Py_Finalize();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

测试显示 PyObject_Print 正在生成崩溃。这段代码和/或我的设置有什么问题?

c++ python c-api python-3.x

2
推荐指数
1
解决办法
2652
查看次数

标签 统计

c++ ×1

c-api ×1

python ×1

python-3.x ×1