Go to the main game directory and type: pyinstaller -onefile main_game_script.py When your game is ready to be wrapped in an EXE, open Windows Command Prompt. To load images into game, call that function, like such: asset_url = resource_path('assets/chars/hero.png') Return os.path.join(base_path, relative_path) # PyInstaller creates a temp folder and stores path in _MEIPASS (I never would have figured out on my own that I needed to add this function to my game, but it works, so thanks to whoever posted it in some other thread) import sys Say the main game file is called main_game_script.py, located in C:\Users\USERNAME\Documents\python\game_dirĪdd this function to main_game_script.py. Open Windows Command Prompt, type: pip install pyinstaller How to create a single file exe of a multi-file python pygame with several asset directories using pyinstaller on Windows: The solution contains bits and pieces of several threads. No one solution worked for me, but after much trial and error I finally stumbled onto a recipe for success and want to share it in case there are other pygame developers out there banging their heads against this. I wrestled with pyinstaller for days, and read all of the threads of others who are also trying to figure it out, and I also read all the pyinstaller docs several times. But I REALLY wanted to package up my python game into a Windows executable. I'm just a scripting hack, and an idiot when it comes to command line tools.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |