简体   繁体   English

使用 cx_Freeze 将我的 python 游戏编译为可执行文件

[英]compiling my python game into executable with cx_Freeze

So i recently finished my first game in pygame, and i wanted to make it into an executable so i can send it to a few of my friends to try, but this has proven harder than i thought, i was recommended to use the cx_Freeze package, but i have run into some issues, ill post my setup code and some screenshots, hopefully someone way smarter than me can give me some advice on this topic.所以我最近在 pygame 中完成了我的第一款游戏,我想把它变成一个可执行文件,这样我就可以把它发给我的几个朋友尝试,但事实证明这比我想象的要难,我被推荐使用 cx_Freeze package ,但我遇到了一些问题,我发布了我的设置代码和一些屏幕截图,希望比我聪明的人能给我一些关于这个主题的建议。

Setup.py:安装程序.py:

from cx_Freeze import setup, Executable
setup( name = "Goblin Evader", version = "3.8",
       description = "A casual game made by mick breiting.",
       executables = [Executable("Goblin Evader.py",
                                 base = "Win32GUI")],
        options = {'build_exe': {'include_files': ['bg.jpg', 'L1.png', 'L1E.png', 'L2.png',
        'L2E.png', 'L3.png', 'L3E.png', 'L4.png', 'L4E.png', 'L5.png', 'L5E.png', 'L6.png',
        'L6E.png', 'L7.png', 'L7E.png', 'L8.png', 'L8E.png', 'L9.png', 'L9E.png', 'L10E.png',
        'L11E.png', 'R1.png', 'R1E.png', 'R2.png', 'R2E.png', 'R3.png', 'R3E.png', 'R4.png',
        'R4E.png', 'R5.png', 'R5E.png', 'R6.png', 'R6E.png', 'R7.png', 'R7E.png', 'R8.png',
        'R8E.png', 'R9.png', 'R9E.png', 'R10E.png', 'R11E.png', 'standing.png']}})

Error:错误:

cx_Freeze 错误

Game directory including setup.py and all assets:游戏目录,包括 setup.py 和所有资产:

游戏目录,包括所有资产文件和 setup.py

I hope anyone knows what to do here, and possibly if there is an easier alternative for this, as i've been trying to learn about it but seem to fall short on good guides, thanks in advance for any help, and sorry im abit of a noob.我希望任何人都知道在这里做什么,并且可能有一个更简单的替代方案,因为我一直在尝试了解它,但似乎缺乏好的指南,提前感谢您的帮助,对不起,我很抱歉一个菜鸟。

I'd give pyinstaller a try instead.我会尝试 pyinstaller。 Much easier to use.更容易使用。 Open cmd prompt in the location of the main python file and run the following:在主 python 文件的位置打开 cmd 提示符并运行以下命令:

pyinstaller pythonfile.py -F --onefile

It will give you an.exe that you can send and use to run the game.它会给你一个.exe,你可以发送并使用它来运行游戏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM