#9 Embedding Paida in C++

critical
closed-works-for-me
Core (7)
5
2007-05-08
2007-05-03
a_rivera
No

Hi,

I'm trying to run Paida from a C++ simple program. I've installed Paida as is described in your web page copying the directory in site-packages and all. Reading the tutorial available in python.org and using the sample code from Paida documentation, I've written this code:

----------------------------------
#include <Python.h>
#include <pythonrun.h>

int
main(int argc, char *argv[])
{
Py_Initialize();
FILE *fp = fopen ("sampleHistogram1D.py", "r+");
PyRun_SimpleFile(fp, "sampleHistogram1D.py");

Py_Finalize();
return 0;
}
-----------------------------------

The compilation is OK (g++ -o runme runme.cpp -I/usr/include/python2.5 -lpython2.5 -ldl -lpthread -lutil -lm) but when I run the resulting executable I get the error log of the attached file.

As running other python programs produce no errors and considering the error output, it seems to me that the problem is in PGuiSelector.py.

I'm working with the python2.5, openSuse10.2 and the latest version of Paida, paida-3.2.1_2.10.

Thanks in advance,

Angela Rivera

Discussion

  • a_rivera

    a_rivera - 2007-05-03

    Error log

     
  • Koji Kishimoto

    Koji Kishimoto - 2007-05-07
    • status: open --> open-accepted
     
  • Koji Kishimoto

    Koji Kishimoto - 2007-05-07

    Logged In: YES
    user_id=734761
    Originator: NO

    Hi Angela,

    Excuse me for the belated reply.

    The problem will be resolved if you add a line:
    PySys_SetArgv(argc, argv);
    next to "Py_Initialize();" in runme.cpp file.

    From Python/C API reference manual, "Py_Initialize()" does not set the argument list (sys.argv) and then we need to call "PySys_SetArgv(argc, argv)".
    Please see http://docs.python.org/api/embedding.html

    Regards,
    Koji Kishimoto

     
  • a_rivera

    a_rivera - 2007-05-08

    Logged In: YES
    user_id=1784250
    Originator: YES

    Hi,

    Thanks a lot for your reply. It has worked all right.

    Regards,

    Angela Rivera

     
  • a_rivera

    a_rivera - 2007-05-08
    • status: open-accepted --> open-works-for-me
     
  • Koji Kishimoto

    Koji Kishimoto - 2007-05-08
    • status: open-works-for-me --> closed-works-for-me
     

Log in to post a comment.