Python API, Initialization, Path and classes

N

nojhan

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_SetProgramName( base_path ); Py_Initialize();
clog << "Python isInitialized ? " << ( Py_IsInitialized()?"yes":"no" ) <<
endl; clog << "Python base program name set:" << Py_GetProgramName() <<
endl; clog << "Python path: " << Py_GetPath() << endl;


But it produce a rather strange output :

Python base program name asked:
/home/nojhan/travail/openMetaheuristic/source/ometah/ometah Python
isInitialized ? yes
Python base program name
set:/home/nojhan/travail/openMetaheuristic/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()
"initializes 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top