How to Convert Pygame to Exe

Problems converting a python pygame into exe

Get py2exe. It is easy to use. Assuming your main script is game.py and that script includes all the other stuff, all you need to do is prepare yet another script, let us call it setup.py and type in:

from distutils.core import setup import py2exe

setup(console=['game.py'])

Now execute that file and it compiles everything into an executable:

python setup.py py2exe

How to make exe of pygame

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:
How can I 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)

Pygame executable not working on another PC

2 possible errors:

1. You forgot to place a file in the .zip

You should use PyInstaller instead of cx_Freeze: you just need to type one line of code in the command prompt, you don't need any other file, and you have the possibility to convert your .py/.pyw file into only one .exe file, without a whole bunch of other files.

This way you can't miss any file in the .zip.



2. You are on win64 and you are sending the program to a win32 computer (or vice versa)

To avoid that issue, you can either:

  1. Reinstall the win32 version of Python
  2. Convert your file to .exe from a win32 computer.

Links to related answers: 1 and 2

How to convert a .py file to .exe file and run on any pc without installing the libraries used in py file?

Thank You @Starbuck5

As @Starbuck5 mentioned in the comment.

These sorts of problems happen when people mix up python installations on their own computer. What’s happened is that the python installation with pygame is not the same installation as the one with PyInstaller. So when PyInstaller runs, it can’t find a pygame to package. –
Starbuck5

I have created a new virtual environment and installed libraries needed for my project and auto-py-to-exe in that virtual env. Then by using auto-py-to-exe, I converted my python file to .exe file and now it's working properly.

You can use any of these methods "auto-py-to-exe", "py2exe" or "pyinstaller", or any other method possible.
Just the libraries should be accessible by pyinstaller or another method you use.

The best way is to do this in a virtual environment.



Related Topics



Leave a reply



Submit