Python API, Initialization, Path and classes
nojhan
nojhan at free.fr
Sun May 14 03:25:51 EDT 2006
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
--
NoJhan
(Cross-posted to comp.python.c++)
More information about the Python-list
mailing list