python - 使用 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
然后什么也没有发生。你能帮我吗?谢谢
解决方案
推荐阅读
- python - 如何使所有子图在情节中具有相同的 xticks 和 yticks?
- python - Python - Google OAuth 从授权码生成令牌
- react-native - 当我在组件中导入信息时,我的应用程序不滚动
- python - 如何按字符比较两个 .txt 文档并量化分数,其中顺序很重要(Python)
- mysql - 非聚合与 MAX 和 GROUP BY
- api - 通过 vpn 记录来自 Postman 的请求(代理/拦截器)
- azure - azure 活动日志的别名
- java - 同一个 IntelliJ 实例中的两个 Spring Boot 模块 - 其中一个未启动
- java - Android 片段更新数据
- javascript - JavaScript 对数组进行排序