gpt4 book ai didi

python - C++ Python 解释器 - Py_Initialize 崩溃

转载 作者:行者123 更新时间:2023-11-28 02:21:01 27 4
gpt4 key购买 nike

我已经编译了 32 位的 python 源代码,并尝试使用 Py_Initialize() API 在我的 C++ 应用程序中初始化 python 解释器。
Py_Initialize() 导致以下崩溃。请帮我解决这个问题。

正在编译我的代码如下:

g++ ./Pythoninterpreter.cpp -m32 -lpthread -ldl -lutil /usr/lib/libm.a /usr/lib/libpython2.7.a -Xlinker -export-dynamic -I/root/python_tar/Python-2.7.6/Include -I/root/python_tar/Python-2.7.6 -o pythonintepreter

gdb back trace
===============

#0 0x080e8ba7 in va_build_value (format=0x8152ec1 "", va=0xffed7564 "\240\344\027\b\244y\355\377", flags=0) at Python/modsupport.c:521
521 memcpy(lva, va, sizeof(va_list));
(gdb) bt
#0 0x080e8ba7 in va_build_value (format=0x8152ec1 "", va=0xffed7564 "\240\344\027\b\244y\355\377", flags=0) at Python/modsupport.c:521
#1 0x080e8ca6 in Py_BuildValue (format=0x8152ebe "[O]") at Python/modsupport.c:485
#2 0x080a77a7 in mro_implementation (type=0x817e4a0) at Objects/typeobject.c:1605
#3 0x080a3d68 in mro_internal (type=0x4) at Objects/typeobject.c:1636
#4 0x080a4723 in PyType_Ready (type=0x817e4a0) at Objects/typeobject.c:4057
#5 0x080a5186 in PyType_Ready (type=0x817e3c0) at Objects/typeobject.c:4005
#6 0x08088252 in _Py_ReadyTypes () at Objects/object.c:2071
#7 0x080ee3f4 in Py_InitializeEx (install_sigs=1) at Python/pythonrun.c:191
#8 0x080eee32 in Py_Initialize () at Python/pythonrun.c:382
#9 0x080598fe in PythonIntepretor::PythonIntepretor(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned short) ()
#10 0x080595fe in main ()
(gdb)

最佳答案

我不完全确定你想做什么,因为你没有在 PythonInterpreter.cpp 上提供代码。

以下代码使用命令行编译:

g++ -I/usr/include/python2.7/-o foo foo.cpp -lpython2.7

#include  "Python.h"
int main()
{
Py_Initialize();
return 0;
}

关于python - C++ Python 解释器 - Py_Initialize 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32472077/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com