Search code examples
pythonoptimizationdistributioncx-freezepyglet

Add a python flag cx_freeze to executable


I'm making a game using pyglet, which runs like a tortoise (~30-35 FPS) unless I pass the -O flag to python when running it (which gives me a smooth 60FPS). I'm planning on using cx_freeze to distribute it, but I need the -O flag to be used every time the game is run. Any ideas?


Solution

  • You can use the same -O flag when you run cx_freeze to generate your final build, meaning that the cx_freeze generated bytecode will already be optimized. From the cxfreeze docs:

    cxfreeze hello.py --target-dir dist Further customization can be done using the following options: ...

    -O optimize generated bytecode as per PYTHONOPTIMIZE; use -OO in order to remove doc strings