467,927 Members | 1,971 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,927 developers. It's quick & easy.

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_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++)

May 14 '06 #1
  • viewed: 916
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

54 posts views Thread by Brandon J. Van Every | last post: by
145 posts views Thread by David MacQuigg | last post: by
10 posts views Thread by Andrew Dalke | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
reply views Thread by fabien.lyon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.