If you execute a program where all the files/modules
are .pyo, that is, compiled while the interpreter had been
started with the -OO command-line option (and presumably -
O as well), then imports fail unless the interpreter had been
started with -OO (-O?) during that run of the program.
Thus, if you want to distribute a program in its smallest form
where you might run a 'build' script that uses the compileall
built-in to create a distribution fileset that comprises
only .pyo files, you'd obviously need to run that script with
the Python interpreter in -OO 'mode'.
When you you try to run the target program from the
distribution fileset, you are required to start the interpreter
in -OO mode or all imports fail since the interpreter does not
search for that extension unless -OO has been used. One
workaround is to rename all the .pyo files to .pyc files, but
this is somewhat silly.... This sitution is undocumented
AFAIK.
Additionally, it would be nice to be able to switch this
optimize mode on/off programmatically. In the app I am
working on (an 'IDE' for Python) I store code objects
(created by using the compile built-in) in the ZODB. If I
have to run the interpreter in -OO mode then I lose debug
information that I'd like to keep. Hence it would be nice to
be able to turn this mode on and off.
|