Python API, Initialization, Path and classes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nojhan

    #1

    Python API, Initialization, Path and classes

    I'm trying to embbed the python interpreter as a class attribute,
    initializing it in the constructor, and finalizing in destructor.

    The code is rather simple:

    // base_path is an attribute of the class, // initialized with argv[0] at
    the instanciation clog << "Python base program name asked: " << base_path
    << endl; Py_SetProgramNa me( base_path ); Py_Initialize() ;
    clog << "Python isInitialized ? " << ( Py_IsInitialize d()?"yes":"no" ) <<
    endl; clog << "Python base program name set:" << Py_GetProgramNa me() <<
    endl; clog << "Python path: " << Py_GetPath() << endl;


    But it produce a rather strange output :

    Python base program name asked:
    /home/nojhan/travail/openMetaheurist ic/source/ometah/ometah Python
    isInitialized ? yes
    Python base program name
    set:/home/nojhan/travail/openMetaheurist ic/source/ometah/ometah Python
    path:
    /usr/lib/python24.zip:/usr/lib/python2.4/:/usr/lib/python2.4/plat-linux2:/usr/lib/python2.4/lib-tk:/usr/lib/python2.4/lib-dynload


    The code ends in an ImportError if I try to import a module in the current
    path.

    Note that the python C API reference manual precise that Py_Initialize()
    "initialize s the module search path (sys.path)" [1].

    I'm searching for a way to force the python interpreter considering the
    current path when searching for available modules.

    [1] http://docs.python.org/api/initialization.html

    --
    NoJhan

    (Cross-posted to comp.python.c++ )

Working...