Embedded python can't import .pyo

Francois Gagnon fgagnon at iphrase.com
Fri Aug 23 19:34:38 CEST 2002


Hi there!

We have an application where we are embedding python into a C runtime engine
and attempting to call our python objects.  Those objects are already
compiled and optimized and we are only keeping the .pyo files.  To be able
to use these python classes, we need to run the interpreter with the -O
option otherwize we get an error: "ImportError: No module named
bin.archive".  So my question is "How can I initialized the python runtime
with the -O option from C?  I did not see any method that allows me to set
the interpreter's flags before calling the Py_Initialize() function.

I had a look into the python source code and found this global variable:
Py_OptimizeFlag.  So I hacked my code a bit to the following which works:

extern int Py_OptimizeFlag;
...
Py_OptimizeFlag++;
Py_Initialize();
...

However, this is not very elegant and risky as future release of Python
could change or use that flag differently.  Are there any API call I can
make to turn the optimize flag on so I can load my .pyo files?  Something
like:

Py_SetOptimize(true);
Py_Initialize();


Thanks
_______________
Francois Gagnon
iPhrase Technologies, One step information access
617-761-6364



More information about the Python-list mailing list