向可执行文件添加 python 标志 cx_freeze

Add a python flag cx_freeze to executable

我正在使用 pyglet 制作游戏,运行它就像一只乌龟(~30-35 FPS),除非我在 运行 时将 -O 标志传递给 python宁它(这给了我一个流畅的 60FPS)。我打算使用 cx_freeze 来分发它,但每次游戏 运行 时我都需要使用 -O 标志。 有什么想法吗?

您可以在 运行 cx_freeze 生成最终版本时使用相同的 -O 标志,这意味着 cx_freeze 生成的字节码已经过优化。来自 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