PYO versus PYC Behavior

Boris Arloff boris.arloff at yahoo.com
Thu Dec 24 10:32:47 EST 2009


All python docs and description indicate that optimization (-OO) does not do much anything except the removal off pydoc. A single "O" removes comments and asserts, and with the removal of pydoc with double "O" option the *.pyo byte compile is left with pure executable code.  I am experiencing a different behavior than described.
 
I am running Python 2.6.4 and have source code which I pre-compile either into pyc or pyo files depending on the optimization switch selected.  The pyo version fails to run with the main program module failing to import any other modules, such as failing on the "import os" statement (first line encountered).  However, the pyc version succeeds and runs correctly.  This is with the same code modules, same python VM and same machine.
 
One item I should note is that the Python distribution I am using is not fully installed with paths set by the installer.  I unpack the Python tar and compile it (i.e. ran configure and make; not make install).  Then I distribute the this Python VM, with its Lib and Modules dirs into my target machine (a Linux distro) and collocate my pyc or pyo modules at the root with python.
 
To further experiment, I have also compiled all python libraries to either pyc and pyo (e.g. os.pyc or os.pyo in the Modules dir).  If I then run with interactive python, I experience the same effect as executing from command line.  Under the IDE "import os" fails if I distribute with python modules compiled into pyo, but it succeeds if I distribute pyc modules.
 
This seems to be contrary to the documentation.  If the only difference was the removal of pydoc between pyc and pyo then both versions should behave exactly the same way.  There must be some additional modifications with a -OO compile.
 
Anyone can comment, please?
 
Thanks,
Boris
 
 


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091224/7bba4bde/attachment-0001.html>


More information about the Python-list mailing list