Search code examples
pythonpygamecx-freeze

Pygame executable not working on another PC


I have created a pygame application and I want to send it to my peers through email. I used cx_Freeze to create executable file. I followed https://pythonprogramming.net/converting-pygame-executable-cx_freeze/ to create the file. It runs perfectly on my laptop but when I zip the entire folder and send it to someone through email and ask them to run on their PC, the executable file crashes by displaying a command window which runs for 1 second and it is unable to view the error. I used the code for creating executable.

import cx_Freeze
import os 

executables = [cx_Freeze.Executable("my_file.py")]
cx_Freeze.setup(
    name="Sample Program",
    options={"build_exe": {"packages":["pygame"],
                           "include_files":[os.path.abspath(os.getcwd()) +"\\my_image.png", 
                           os.path.abspath(os.getcwd()) + "\\data\\"]}},
    executables = executables

    )

I do not want them to go through any installation process for Python or Pygame. How can I fix this and make it run in every other PC ?


Solution

  • 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