Skip to content

Optimized bytecode

Problem

If you specify the optimize option in your setup.py, this will only be used for the compiling of the needed modules, not for your main module!
For example if you have the following setup.py:

from distutils.core import setup
import py2exe

setup(
    options={"py2exe":{"optimize":2}},
    console=["beep.py"]
)

The bytecode embedded in the resulting .exe will not be optimised.

Solution

To get optimized bytecode, you need to call the setup.py like so:

python -OO setup.py py2exe