How to convert multiple python files to EXE

Multi tool use
How to convert multiple python files to EXE
I am trying to convert my python game - space invaders into an exe. I have seen py2exe and cx_freeze but they seem to compile only 1 singe py file. I also have a bunch images from which I load from 2 resource folders that the modules depend on. Can anyone please help me? Thanks.
https://i.stack.imgur.com/y6h7M.png
2 Answers
2
Easy. Just use the cx_freeze script but modify its scope. Include the pygame libraries, add the tkinter dependency, and include the game file directory.
import cx_Freeze
import sys
import os
# Include TK Libs
os.environ['TCL_LIBRARY'] = r'C:UsersyourusernameAppDataLocalProgramsPythonPython36tcltcl8.6'
os.environ['TK_LIBRARY'] = r'C:UsersyourusernameAppDataLocalProgramsPythonPython36tcltk8.6'
executables = [
cx_Freeze.Executable(
script="yourClientFile.pyw", # .pyw is optional
base = "Win32GUI"
)
]
cx_Freeze.setup(
name='myName',
options={'build_exe':{'packages':['pygame'], 'include_files':['yourGameDataDirectoryHere']}},
executables = executables,
version = '1.0.0'
)
Note that this will only work with this type of file structure:
Client.py (Runs game off src)
src - |
Game Files here
I'm personally familiar with pyinstaller, this is done via the "--onefile" parameter
However for py2exe it has been explained here,
https://stackoverflow.com/a/113014/9981387
I would prefer to not give out my email, As you have installed py2exe, I will assume you can run "pip install pyinstaller", with this done, you run "pyinstaller --onefile FILE" File being your main python file, it will then complie it down to 1 file, and put it in the "dist" folder of your python installation.
– Reroute
Jul 2 at 13:42
Thanks but I just found out that the --onefile parameter is used to package everything into a single executable file, so that you dont have separate ones for libraries etc. ( according to the pyinstaller documentation). But my issue isn't that I want a single executable file, I just want to compile ALL of my PYTHON FILES into that executable. So I have 4 modules the primary calling module which is main, and then I have the 3 game modes human, alien,coop.
– Yasin Khan
Jul 2 at 13:43
Ok to clarify, the --onefile compiles the main file and all of its imports into a single executable, meaning the .exe will run exactly like when you press run for that file in your IDE, if you want different .exe files for different options, then run pyinstaller on the file you would run to get the result you desire.
– Reroute
Jul 2 at 13:47
ah yep I see thanks ill try it if I get any errors ill let u know
– Yasin Khan
Jul 2 at 14:11
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
sorry could u explain the --onefile parameter, and if possible would u be kind enough to compile the files if I gave them to you via email, my executable is due tomorrow so I would be everso grateful :)
– Yasin Khan
Jul 2 at 13:33