Search code examples
pythonoptimizationcx-freeze

What are the optimization levels in Cx_Freeze?


I'm freezing my scripts with Cx_Freeze 6.0 (Python 3.7.4 64 bit if that makes any difference) and I'm struggling to find any documentation about the optimization levels in build_exe. Most scripts I see use either 1 or no value at all, I've used 1 and 2 successfully and I can't spot any difference in the exe.

My current options look something like this:

exe_options = {
    'build_exe': 'bin',
    'includes': ['something'],
    'excludes': ['something_else'],
    'packages': ['pack', 'age'],
    'optimize': 2  # What the hell are the levels?
}

Edit: I checked an MD5 hash and a SHA-256 hash on the exe files, with levels 0,1 and 2, the exe is the exact same file. Is this option just unused when running "build"?


Solution

  • This has the same effect as the -O command line option when executing CPython directly. Among other things, it prevents assert statements from executing, remove docstrings and set __debug__ to False.