0

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"?

Ofer Sadan
  • 11,391
  • 5
  • 38
  • 62

1 Answers1

2

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.

user2722968
  • 13,636
  • 2
  • 46
  • 67
  • But that doesn't explain why the results are identical for exe files built with different levels. If `__debug__` is set to `False`, for example, shouldn't the exe hash be different? – Ofer Sadan Sep 16 '19 at 08:00
  • Did you try freezing with code that actually depends on `__debug__`? You can also query `sys.flags.optimize`, which should give back the value you passed to `cx_freeze`. – user2722968 Sep 16 '19 at 10:06