I have written a game with Python3 using Pygame module. Now I want to create an executable of the game for Mac Os so that I can distribute it.
Asked
Active
Viewed 1,163 times
0
-
try this https://www.pygame.org/wiki/MacCompile – sleepyhead Oct 19 '20 at 08:11
2 Answers
1
Try doing this and report if it works:
pip3 install pyinstaller
navigate to project directory
pyinstaller --onefile insertfilenamehere.py

Glatinis
- 337
- 1
- 13
0
This question has been anwsered here : How can I convert pygame to exe?
But basically what you want to do is :
1 - Install pyinstaller :
pip install pyinstaller
2 - Deal with static assets such as images with this code :
import sys
import os
def resource_path(relative_path):
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
Then to load the images in the game you call your function
asset_url = resource_path('assets/chars/hero.png')
hero_asset = pygame.image.load(asset_url)
3 - Finally, you can create an executable from your .py file by typing the following in a CMD inside of your game directory :
pyinstaller --onefile main_game_script.py

eden annonay
- 37
- 1
- 8