0

I've finished developing my game in pygame and I want to make a exe of it so I can share it. I tried using cx_Freeze for making exe but in that tutorial he just added only single image and I was confused how I must add these many sprites in a single line I followed this tutorial - https://www.youtube.com/watch?v=BIWqt6NICrw&t=49s

In this tutorial he adds only single image file since his game is too small. So I tried different ways. I tried this method - How can I convert pygame to exe? But its too complex and when I try to perform it I get so many syntax error (I tried that method 10 times)

All I can see there is only one way left to develop exe of my pygame using cx_Freeze but I don't know how to do so. And I'm using python3 (ver:3.7.3)

Can anyone explain me step by step how to make game using cx_Freeze (please also let me know how to add multiple images since i got so many images (sprites) each for different enemies and hero)

ErikDM
  • 78
  • 4
hotstepper
  • 39
  • 6
  • Something like this? https://stackoverflow.com/questions/5458048/how-to-make-a-python-script-standalone-executable-to-run-without-any-dependency – mrfr Jul 12 '19 at 06:20
  • Im talking about pygame not python script- this method won't work here – hotstepper Jul 12 '19 at 06:27
  • Pygame is just a library that you can include in your python script. Perhaps elaborate why that method wont work? – mrfr Jul 12 '19 at 06:29
  • pygame is a python library so this will work... maybe you have to configure a bit more but python is python. I succesfully used py2exe for Python GUIs made with Qt using third party libraries multiple times. – Mailerdaimon Jul 12 '19 at 06:29

3 Answers3

1

Pyinstaller is also being used to make exe, I don't know if it will help in your case or not.

1

This has already been answered a few times before, converting a pygame to exe is same as converting other python gui applications.

a link to one of the previous questions: Create a directly-executable cross-platform GUI app using Python

A addition to the Aakash Mehta's answer, relating to this link: https://pythonprogramming.net/converting-pygame-executable-cx_freeze/

If you want to add more files, you need to add them to the include list:

cx_Freeze.setup(
name="A bit Racey",
options={"build_exe": {"packages":["pygame"],
                       "include_files":["racecar.png", "add_files.png", "one_more.png"]}}, # This line
executables = executables)
Community
  • 1
  • 1
Mattias
  • 416
  • 4
  • 12
  • I got so many images - is there any shortcut to import those images? – hotstepper Jul 12 '19 at 07:28
  • you can use the os module, put all images in one folder and just loop through all names of the images in that folder. Or use this answer: https://stackoverflow.com/questions/15079268/how-can-i-include-a-folder-with-cx-freeze – Mattias Jul 12 '19 at 07:33
  • can you explan me how to do it by first method please – hotstepper Jul 12 '19 at 07:57
  • Heres a tutorial on it:https://www.tutorialspoint.com/python/os_listdir If my answer is satisfactory please accept my answer. – Mattias Jul 12 '19 at 09:31
  • I figured it out how to use os.path but im still not able to make exe using cx_Freeze – hotstepper Jul 12 '19 at 09:33
  • if there is any other way then let me know please – hotstepper Jul 12 '19 at 09:33
  • look through the first link I posted. – Mattias Jul 12 '19 at 13:03
  • Everything is going good but after I make exe using cx_Freeze and try to open it - it opens and closes CMD. I've been searching for fix everywhere but no luck - do you have any way to fix it? – hotstepper Jul 12 '19 at 14:29
  • i tried running that exe by using CMD and I get error - Failed to execute script mygame and its pointing to pygame.error: Couldn't open LongBGx5.png but when i run game using pycharm it runs properly without any errors – hotstepper Jul 12 '19 at 15:18
  • Sound like another problem, open up another issue and add that log when asking a question. As it seems my answer was satisfactory, please accept my answer. – Mattias Jul 15 '19 at 08:15
0

According to this website https://pythonprogramming.net/converting-pygame-executable-cx_freeze/ You can use a module called cx_Freeze which is similar to py2exe. Some of the steps are similar to py2exe And all the instructions are on the website.

  • that person developed a simple game which contain only one image file, he didn't explained what to do if there are multiple image files each for character. – hotstepper Jul 12 '19 at 06:54