Having problems with making an .exe with cx_freeze with python and pygame, including additional files

旧城冷巷雨未停 提交于 2020-01-23 03:56:06

问题


I'm having trouble creating an .exe file with cx_Freeze. I'm trying to use this Pygame game which needs some .png's, .gif's and .ogg's to run. I have tried to compile a simple Python only (no pygame or additional files) using the commmand line and a setup.py, but neither worked and I'm a bit out of my death.

I have installed cx_Freeze and checked it worked with ''import cx_freeze' in the IDLE not throwing an error. I'm using Python 3.3 on Windows 7 with the correct versions of pygame and cx_freeze for my python version.

Can anyone assist me in creating this .exe?


回答1:


To include files in your .exe you should write a setup.py file that is similar to this:

from cx_Freeze import setup, Executable

exe=Executable(
     script="file.py",
     base="Win32Gui",
     icon="Icon.ico"
     )
includefiles=["file.ogg","file.png",etc]
includes=[]
excludes=[]
packages=[]
setup(

     version = "0.0",
     description = "No Description",
     author = "Name",
     name = "App name",
     options = {'build_exe': {'excludes':excludes,'packages':packages,'include_files':includefiles}},
     executables = [exe]
     )


来源:https://stackoverflow.com/questions/16065060/having-problems-with-making-an-exe-with-cx-freeze-with-python-and-pygame-inclu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!