[docs] Python Doc bug, 5.3 Pure Emebedding

Bob Reese reese at ece.msstate.edu
Sat Dec 4 15:06:55 CET 2010

FYI (great job on documentation!!) 

5.3 Pure Embedding code example. 

This is a good example but under 2.3 and 2.6 on my Linux systems, the example fails to run because the sys.path variable does not have the current working directory ('[]') on it, so the module is not found (the python code is in the cwd). I am not sure why this occurs, because if the normal python interpreter is executed and the sys.path variable printed, the current working directory is on that path. 

I don't know why starting up the interpreter under C code control produces a different sys.path value from starting up the Python interpret from a shell command line (everything is the same except for the cwd being present). 

Somebody else in web land has also experienced this problem, as evidenced by (this is the same behavior that I see): 

The real fix would be to identify what is causing this difference in sys.path values, but I have not been able to do this. It is probable that this is just an environment issue of some kind, but I don't know what it is. 

My bogus fix is to modify the example to add the current working directory to the sys.path variable as follows: 

void fixSysPath(void) { 
PyObject *pSysModule; 
PyObject *pSysPath; 
PyObject *pCwd; 
int i; 

pSysModule = PyImport_ImportModule("sys"); 
if (pSysModule == NULL) { 
myErr("Import of sys module failed"); 

pSysPath = PyObject_GetAttrString(pSysModule, "path"); 
if (!pSysPath) { 
myErr("Cannot find 'sys.path'"); 
pCwd = PyString_FromString(""); //null string represents cwd 


And in the example....: 
fixSysPath(); //<<<<---Added 

Thanks. Great job on the documentation! 

Bob Reese 662/325-3154 (voice) 
reese at ece.msstate.edu 662/325-2298 (fax) 
Associate Prof/Electrical & Computer Engineering 
Mississippi State University 
US Mail Address: 
Box 9571, Miss State, MS 39762 
Street Address: 
309 Simrall Hall, Hardy Street, Miss State, MS 39762 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20101204/a5539c14/attachment.html>

More information about the docs mailing list