Python Forum
How to create .exe with PyGame [BEGINNER]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create .exe with PyGame [BEGINNER]
#1
Question 
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!
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  beginner needs PyGame advice barryjo 4 1,800 Dec-04-2021, 11:21 AM
Last Post: snippsat
  Pygame*import pygame ImportError: No module named pygame CASPERHANISCH 1 9,755 Jun-05-2017, 09:50 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020