0

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?

3
  • Can you be more specific about the problems you're having? Start with the simple Python file - what do you do? Do you see any errors?
    – Thomas K
    Apr 17, 2013 at 17:09
  • @Thomas K I just don't know what to put in setup.py and how to include the files and what to do with the 'diff' or 'build' folders - the cx_Freeze documentation I've found online is Yiddish to me... I really need someone to walk me through it.
    – jellyberg
    Apr 17, 2013 at 17:52
  • You can try running cxfreeze-quickstart to create a setup.py file. If that doesn't work, there's an example file shown here that you could copy and modify.
    – Thomas K
    Apr 17, 2013 at 21:35

1 Answer 1

5

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]
     )
7
  • Thanks that's fantastic. Would pygame be a package or an includes? And would I put other native modules I've imported like time and random in there too? Thanks again.
    – jellyberg
    Apr 17, 2013 at 19:07
  • From my experiences you don't need to add pygame anywhere. My exe works when i don't put pygame anywhere in the setup.py script. The same goes with the other modules.
    – Anthony
    Apr 17, 2013 at 19:29
  • Yes, you must first change to the directory with the files in it, then type 'python setup.py build'.
    – Anthony
    Apr 17, 2013 at 19:53
  • I'm assuming you mean Windows cmd line. It says: 'python' is not recognised as an internal or external command, operable program or batch file. Any ideas?
    – jellyberg
    Apr 17, 2013 at 20:48
  • Yes windows cmd line. That's interesting. I'm not sure. It works on my computer. Perhaps it is a python 3.3 thing. (I have python 3.2). Where have you installed python? Try typing in the full location (e.g. C:\python\python.exe) instead of just "python". I am not exactly sure if this will work but it's worth the shot.
    – Anthony
    Apr 17, 2013 at 20:58

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.