Giorgi Papava
Giorgi Papava

Reputation: 43

Want to convert pygame project to windows executable file

I created python game with pygame from book called 'Python crash course'. It has 9 .py file (1 to run game, other 8 for modules like: settings, game_functions, etc.) and one folder where are 2 image files. I want to share this project with my friends who don't have python and pygame, so I want to convert entire project to .exe (windows executable)

I have tried cx_Freeze, py2exe and pyinstaller. Pyinstaller was the most successful one, It created .exe file but however when I run it it's getting black screen and getting closed. I think the reason is that it can't reach modules (8 .py files) and/or image files that I'm using.

Here is main .py code, whats it importing and stuff..

import pygame
from pygame.sprite import Group
from settings import Settings
from ship import Ship
import game_functions as gf
from game_stats import GameStats
from scoreboard import Scoreboard
from button import Button


def run_game():
        pygame.init()
...

If you need any additional information feel free to ask!

Upvotes: 1

Views: 1878

Answers (1)

LeSeulArtichaut
LeSeulArtichaut

Reputation: 93

First of all, let me recommand you to use Markdown whenever you have code to show; it is really simple, and makes it really easier to read. For example, add ```python before your code and ``` at the end. Code will be formatted and will have syntax highlighting. For example, instead of being shown on one single line, your code becomes:

import pygame
from pygame.sprite import Group
from settings import Settings
from ship import Ship
import game_functions as gf
from game_stats import GameStats
from scoreboard import Scoreboard
from button import Button

def run_game(): pygame.init() ...

Now, onto your issue. According to the cx_Freeze documentation:

Different bases serve for different types of application on Windows (GUI, console application or service).

With cx_Freeze, you need to specify the application is a GUI (Graphical User Interface) in the setup.py file, like:

import sys
from cx_Freeze import setup, Executable

# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(  name = "guifoo",
        version = "0.1",
        description = "My GUI application!",
        executables = [Executable("guifoo_main.py", base=base)])

I haven't checked all of the other "python to standalone app converters", but I guess there might be something similar that needs to be changed for the app to be executed correctly, and not as a console app. When this kind of issues happen, I suggest you to take the time to read it's documentation carefully.

Hope that helps!

Upvotes: 1

Related Questions