run python code in c++
Question: I was making an app that needs to run python code in c++. But when I run this
code it gives an segmentation fault in 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();
    


Answer: 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);  
        // ...
    

