Back

Explore Courses Blog Tutorials Interview Questions

Explore Tech Questions and Answers

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

0 votes
2 views
by (19.9k points)

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 -

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)

1 Answer

0 votes
by (25.1k points)

First, you will want to make a setup.py file with the following contents:

import cx_Freeze

executables = [cx_Freeze.Executable("pygameVideo15.py")]

cx_Freeze.setup(

    name="A bit Racey",

    options={"build_exe": {"packages":["pygame"],

                           "include_files":["racecar.png"]}},

    executables = executables

    )

 

The above is converting the python script contained under the file name: pygameVideo15.py

From there, we specify the name of the application, then we explicitly notify cx_Freeze that we are using the pygame module, and we explicitly tell it that we have an included file, which is racecar.png.

cx_Freeze can sometimes figure out modules that you're using, but sometimes not. Following with typical Pythonic precepts, explicit is better than implicit, so let's be clear!

Once you've done that, you'll want to navigate to your terminal and make your way to the directory containing your Python game script and the setup.py script.

Then, type:

python setup.py build.

If you get an error stating that Python is not in your path, then give the full path. For example, on Windows, with Python 3.4, you would do:

C:/Python34/python setup.py build

From there, you should get a build directory, within it will be an executable that will run your script.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Nov 28, 2020 in Python by ashely (50.2k points)
0 votes
1 answer
0 votes
1 answer
asked Nov 25, 2019 in Python by Sammy (47.6k points)

Browse Categories

...