Python Forum

Full Version: How to create .exe with PyGame [BEGINNER]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone,

I have looked through so many online guides, blogs, and tons of questions on Stackexchange and so, but I can't seem to find an answer. Now I've come here, hope you guys can help.

First off, I am not new to python, but I am new to command line and creating .exe files.

What I want to do: Create .exe file from a .py file with PyGame
I have the game directory Simple Race. race1.py is my main file. images is a folder containing all images used for the game. Runs using PyGame Zero, newest version of Python (3.7.x??). I want to create an application for Windows so I can run the game without opening IDLE and such, also for sharing the game.
Using pyinstaller --onefile race1.py in my Simple Race directory has I believe not worked. When I run, a terminal window (blank) opens.

So how do I create a .exe file in this scenario? Does someone have a simple answer, or can someone at least explain the necessary steps I would use in my case.

Here are some photos of my scenario:
Simple Race directory:
[Image: annotation2020-03-122y5ke4.png]
Inside Simple Race:
[Image: image.php?img=annotation2020-03-1221fjm9.png]
Inside images:
[Image: image.php?img=annotation2020-03-122e8kgq.png]
When running the .exe that I created using pyinstaller:
[Image: image.php?img=annotation2020-03-122ffjfy.png]

[EDIT]: The last three images do not work! Please double click on the broken image icon to get the image to display!!

Thank you so much!
Look at this post,a working test of pygame with pyinstaller.
(Mar-13-2020, 01:25 AM)PolarBear123 Wrote: [ -> ]When running the .exe that I created using pyinstaller:
That's just the folder setup,you know that the .exe is in dist folder?

You have some extra file that need to be added this can be done from command line or in spec file.
Example:
pyinstaller --onefile --add-data="path/to/images/*;." race1.py
So if i would add images folder to pong game in post linked,working test.
pyinstaller --onefile --noconsole --add-data="E:/div_code/pygame_env/images/*;images" pong.py

# Use --onedir to see that images folder has been added
pyinstaller --onedir --noconsole --add-data="E:/div_code/pygame_env/images/*;images" pong.py