[英]run python code in c++
I was making an app that needs to run python code in c++. 我正在制作一个需要在C ++中运行python代码的应用程序。 But when I run this code it gives an segmentation fault in Linux. 但是,当我运行此代码时,它在Linux中给出了分段错误。 Does somebody have a clue what it could be? 有人知道这可能是什么吗?
Py_SetProgramName("programName");
Py_SetPythonHome("/usr/lib/python2.7");
Py_Initialize();
PyRun_SimpleString("import sys");
Py_Finalize();
Use as follows: 用法如下:
#include <Python.h> // Attention: this MUST always be the first file included
int main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]); // optional but recommended
Py_Initialize();
PySys_SetArgv(argc, argv);
// ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.