首页 > 解决方案 > 使用 cx_Freeze 将 pygame 转换为 exe

问题描述

我以前没有任何使用 pygame 的经验,但是通过遵循在线教程,我设法创建了 Flappy Bird 游戏。我想把脚本变成一个 .exe 文件与我的朋友分享。我创建了一个 setup.py 文件,如下所示:

import cx_Freeze
import os

executables = [cx_Freeze.Executable("script.py")]

assets = ['res/assets/' + each for each in os.listdir('C:/Users/MehmetSanisoglu/Desktop/Game/res/assets')]
sounds = ['res/sound/' + each for each in os.listdir('C:/Users/MehmetSanisoglu/Desktop/Game/res/sound')]
files = assets + sounds
files.append('res/04B_19.TTF') #Add the font file

cx_Freeze.setup(
    name="Flappy",
    options={"build_exe": {"packages":['pygame','sys','random'],
                           "include_files":files}},
    executables = executables
)

但是,当我在 script.py 和 setup.py 所在的目录中运行 cmd 时,在创建的构建文件中我找不到“Flappy.exe”,但有一个“script.exe”。当我运行 script.exe 时,它​​会在一瞬间打开一个命令行,在其中我可以看到以下几行:

running build
running build_exe
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html

然后什么也没有发生。你能帮我吗?谢谢

标签: pythonpygameexecutablecx-freeze

解决方案


推荐阅读