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 py2exeNow execute that file and it compiles everything into an executable:
setup(console=['game.py'])
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:- Reinstall the win32 version of Python
- 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
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.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
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
Why Results of Map() and List Comprehension Are Different
Spark Dataframe: Computing Row-Wise Mean (Or Any Aggregate Operation)
Numpy Argsort - What Is It Doing
Increment Numpy Array with Repeated Indices
Python Pandas, Write Dataframe to Fixed-Width File (To_Fwf)
How to Download a File from Google Drive Using Python and the Drive API V3
Loading Initial Data with Django 1.7 and Data Migrations
How to Get a List of Keywords in Python
Make Part of a Matplotlib Title Bold and a Different Color
Asyncio: How to Cancel a Future Been Run by an Executor
How to Use a Default Namespace in an Lxml Xpath Query
How to Access Class Member Variables in Python
How Does the Max() Function Work on List of Strings in Python
Check If an Item Is in a Nested List
Pyspark Dataframes - Way to Enumerate Without Converting to Pandas
How to Obscure a Line Behind a Surface Plot in Matplotlib
In Python, What Happens When You Import Inside of a Function