【发布时间】:2013-03-09 23:42:28
【问题描述】:
我正在使用 Python 3.2 和 Pygame 制作游戏。我已经成功地使用cx_freeze 将所有内容捆绑到一个可执行文件中,并且它运行了。美好的。唯一的问题是,即使我将-OO 标志传递给我的setup.py,我的游戏也会在调试模式下编译。(我已经用print 声明__debug__ 确认了这一点确实是True。)
问题是,我的游戏具有在发布模式下自动禁用的调试功能。我不想分发我的游戏的调试功能,也不想手动从代码中删除它们。
我的setup.py,为简洁起见,如下:
from cx_Freeze import setup, Executable
includes = [<some modules>]
excludes = [<some unwanted modules>]
include_files = [<game assets>]
build_options = {
'append_script_to_exe':True,
'bin_excludes':excludes,
'compressed':True,
'excludes': excludes,
'include_files': include_files,
'includes': includes,
'optimize':2,
'packages': ['core', 'game'],
}
common_exe_options = {
'appendScriptToExe' : True,
'appendScriptToLibrary':True,
'compress' : True,
'copyDependentFiles' : True,
'excludes' : excludes,
'includes' : includes,
'script' : '__init__.py',
}
executable = Executable(**common_exe_options)
setup(name='Invasodado',
version='0.8',
description='wowza!',
options = {'build_exe': build_options,
'bdist_msi': build_options},
executables=[executable])
完整的脚本和我的其他代码一样,可以在https://github.com/CorundumGames/Invasodado/blob/master/setup.py 找到。
在 Ubuntu 12.10 上,我正在使用 python3.2 -OO setup.py build 构建。在 Windows XP 上,我使用 C:\Python32\python -OO setup.py build 构建。
任何帮助都会很棒!
【问题讨论】:
-
这对于 opengl 代码来说是一个大问题:如果我没记错的话,像 pyglet 和 pyopengl 之类的东西,如果没有优化运行,会在运行时执行大量昂贵的安全检查,从而将代码减慢幅度。
标签: python debugging python-3.x pygame cx-freeze