Pyinstaller, .exe file does nothing

After 5 days of thinking what wasnt working, finally i came here for any advice.

main.py:

import pygame
from pygame.sprite import Group
from Settings import Settings
from Player import Character
import Game_Functions as gf
from pygame.locals import *
from Hp_Bar import HP_Bar
from pygame.math import Vector2
from Game_stats import GameStats
from Button import Button
from Scoreboard import Scoreboard
import sys
import os


def main():
    def resource_path(relative_path):
        if hasattr(sys, '_MEIPASS'):
            return os.path.join(sys._MEIPASS, relative_path)
        return os.path.join(os.path.abspath("."), relative_path)


pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.SCREEN_WIDTH, ai_settings.SCREEN_HEIGHT))
clock = pygame.time.Clock()
pygame.display.set_caption("Space Shooter")
player = Character(ai_settings, screen)
# Utworzenie grupy przeznaczonej do przechowywania pocisków.
new_bullet = Group()
boss_bullet = Group()
all_sprites = Group()
aliens = Group()
starr = Group()
deszcz = Group()
bosss = Group()
# enemyPlayer = Group()
gf.create_fleet(ai_settings, screen, player, aliens)
gf.create_fleet_drop(ai_settings, screen, player, deszcz)
gf.create_boss(ai_settings, screen, bosss, player, boss_bullet, all_sprites)
stats = GameStats(ai_settings)
pause_button = Button(ai_settings, screen, "Pause")
clock = pygame.time.Clock()
fps = 60
pos = Vector2()
HPbar = HP_Bar(ai_settings, screen, bosss)
background = pygame.image.load(resource_path('lol6.png'))
pygame.mixer.music.load(resource_path("music.wav"))
pygame.mixer.music.play(-1)
extra_bullet = Group()
explosion = Group()
# gf.AniExplosion(explosion, bosss)
# gf.create_bosss(ai_settings, screen, aliens, bosss, boss_bullet, new_bullet, extra_bullet, HPbar, player,
# explosion)
menu = True
menu2 = True
loop = True
background1 = pygame.image.load(resource_path('background11.png'))
image1 = pygame.image.load(resource_path('youwin2.png'))
youlost = pygame.image.load(resource_path('youlost2.png'))
myfont = pygame.font.SysFont(None, 25)
minutes = 0
seconds = 0
miliseconds = 0
sb = Scoreboard(ai_settings, screen, stats)
# GŁÓWNA PĘTLA GRY

while loop:
    timelabel = myfont.render("{}:{}:{}".format(minutes, seconds, miliseconds), 1, (70, 0, 90))
    txt = myfont.render("TIME:  {}:{}:{} ".format(minutes, seconds, miliseconds), 1, (70, 0, 90))
    if miliseconds > 1000:
        seconds += 1
        miliseconds = 0
    miliseconds += clock.get_rawtime()
    if seconds > 60:
        minutes += 1
        seconds -= 60
    if player.health <= 0 or stats.ships_left <= 0:
        while menu2:
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.key == K_g:
                        menu2 = False
                        main()
            miliseconds -= miliseconds
            gf.time_txt(screen, txt, youlost)
            pygame.display.update()
    for expl in explosion:
        if HPbar.Health <= 4 and expl.index >= 9:
            while menu2:
                for event in pygame.event.get():
                    if event.type == pygame.KEYDOWN:
                        if event.key == K_g:
                            menu2 = False
                            main()
                clock.tick(30)
                screen.fill((0, 0, 0))
                screen.blit(image1, (0, 0))
                screen.blit(txt, (510, 500))
                pygame.display.update()

    while menu:
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == K_p:
                    menu = False
        clock.tick(30)
        screen.fill((0, 0, 0))
        screen.blit(background1, (0, 0))
        pygame.display.update()
    screen.blit(background, (0, 0))
    screen.blit(timelabel, (500, 10))

    gf.check_events(ai_settings, screen, player, new_bullet, boss_bullet, bosss, pos, HPbar,
             extra_bullet, stats)

    if stats.game_active:

        player.update()
        new_bullet.update()
        gf.update_bullets(ai_settings, stats, sb, new_bullet, aliens)
        gf.update_rain(ai_settings, deszcz)
        gf.update_aliens(ai_settings, stats, sb, screen, player, aliens, new_bullet)
        boss_bullet.update()
        gf.boss_bullet_update(ai_settings, boss_bullet)
        extra_bullet.update()
        gf.extra_bullet_update(ai_settings, extra_bullet)
        gf.update_animation(explosion)
    gf.update_boss(ai_settings, bosss)
    gf.update_screen(ai_settings, screen, player, bosss, deszcz, aliens, starr, new_bullet, boss_bullet,
                     HPbar, extra_bullet, explosion, stats, sb, pause_button)
    if not stats.game_active:
        miliseconds = int(float(".{}".format(miliseconds)))


    clock.tick(fps)

   if __name__ == '__main__':
       main()

My final commad to build .exe:

pyinstaller --onefile --debug=all --noupx --add-data "alien7.png;." --add-data "animations*.png;." --add-data "lol6.png;." --add-data "boss1.png;." --add-data "bossbullet.png;." --add-data "BossDestroyed.wav;." --add-data "ExtraBullet.png;." --add-data "hit.wav;." --add-data "hit2.wav;." --add-data "hitboss.wav;." --add-data "kolo5.png;." --add-data "lol6.png;." --add-data "music.wav;." --add-data "youlost2.png;." --add-data "youwin2.png;." --add-data "background11.png;." MainGame.py

Yea, maybe its not perfect form, but i only wanna run it from exe. With --onefile at end shows error:

"[7032] LOADER: Back to parent (RC: -1073741819)
[7032] LOADER: Doing cleanup
[7032] LOADER: Freeing archive status for C:\Users\Kamil\PycharmProjects\pythonProject\dist\MainGame.exe"

And warn log:

    missing module named 'win32com.gen_py' - imported by win32com (conditional, optional), c:\users\kamil\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_win32comgenpy.py (top-level)
missing module named 'org.python' - imported by copy (optional), setuptools.sandbox (conditional), xml.sax (delayed, conditional)
missing module named importlib.metadata - imported by importlib (conditional), pluggy.manager (conditional), PyInstaller.utils.hooks.conda (conditional), _pytest.compat (conditional)
missing module named _frozen_importlib_external - imported by importlib._bootstrap (delayed), importlib (optional), importlib.abc (optional)
excluded module named _frozen_importlib - imported by importlib (optional), importlib.abc (optional), PyInstaller.loader.pyimod02_archive (delayed)
missing module named pwd - imported by posixpath (delayed, conditional), shutil (optional), tarfile (optional), http.server (delayed, optional), webbrowser (delayed), pathlib (delayed, conditional, optional), distutils.util (delayed, conditional, optional), distutils.archive_util (optional), netrc (delayed, conditional), getpass (delayed), py._path.local (delayed)
missing module named urllib.quote - imported by urllib (delayed), py._path.svnwc (delayed)
missing module named urllib.pathname2url - imported by urllib (conditional), PyInstaller.lib.modulegraph._compat (conditional)
missing module named termios - imported by tty (top-level), getpass (optional), py._io.terminalwriter (delayed, conditional)
missing module named _posixsubprocess - imported by subprocess (conditional), multiprocessing.util (delayed)
missing module named vms_lib - imported by platform (delayed, conditional, optional)
missing module named 'java.lang' - imported by platform (delayed, optional), xml.sax._exceptions (conditional)
missing module named java - imported by platform (delayed)
missing module named _scproxy - imported by urllib.request (conditional)
missing module named _winreg - imported by platform (delayed, optional), pygame (conditional), pygame.sysfont (conditional), numpy.distutils.cpuinfo (delayed, conditional, optional), pkg_resources._vendor.appdirs (delayed, conditional)
missing module named readline - imported by cmd (delayed, conditional, optional), code (delayed, conditional, optional), pdb (delayed, optional), _pytest.capture (delayed, conditional, optional)
missing module named org - imported by pickle (optional)
missing module named grp - imported by shutil (optional), tarfile (optional), pathlib (delayed), distutils.archive_util (optional), py._path.local (delayed)
missing module named pyimod03_importers - imported by c:\users\kamil\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_pkgres.py (top-level)
missing module named 'six.moves.urllib'.parse - imported by 'six.moves.urllib' (top-level), packaging.requirements (top-level)
runtime module named six.moves - imported by 'six.moves.urllib' (top-level)
missing module named StringIO - imported by setuptools._vendor.six (conditional), PyInstaller.lib.modulegraph._compat (conditional), PyInstaller.lib.modulegraph.zipio (conditional), numpy.lib.utils (delayed, conditional), numpy.lib.format (delayed, conditional), numpy.testing._private.utils (conditional), py._io.capture (optional), pkg_resources._vendor.six (conditional), six (conditional)
missing module named 'six.moves.urllib' - imported by 'six.moves.urllib' (top-level)
missing module named _uuid - imported by uuid (optional)
missing module named __builtin__ - imported by numpy.core.numerictypes (conditional), numpy.core.numeric (conditional), numpy.lib.function_base (conditional), numpy.lib._iotools (conditional), numpy.ma.core (conditional), numpy.distutils.misc_util (delayed, conditional), numpy (conditional), py._builtin (conditional), pkg_resources._vendor.pyparsing (conditional), pyparsing (conditional), setuptools._vendor.pyparsing (conditional)
missing module named ordereddict - imported by pkg_resources._vendor.pyparsing (optional), pyparsing (optional), setuptools._vendor.pyparsing (optional)
missing module named _manylinux - imported by setuptools.pep425tags (delayed, optional), packaging.tags (delayed, optional)
missing module named 'pkg_resources.extern.pyparsing' - imported by pkg_resources._vendor.packaging.markers (top-level), pkg_resources._vendor.packaging.requirements (top-level)
missing module named 'com.sun' - imported by pkg_resources._vendor.appdirs (delayed, conditional, optional)
missing module named com - imported by pkg_resources._vendor.appdirs (delayed)
missing module named pkg_resources.extern.packaging - imported by pkg_resources.extern (top-level), pkg_resources (top-level)
missing module named pkg_resources.extern.appdirs - imported by pkg_resources.extern (top-level), pkg_resources (top-level)
missing module named 'pkg_resources.extern.six.moves' - imported by pkg_resources (top-level), pkg_resources._vendor.packaging.requirements (top-level)
missing module named pkg_resources.extern.six - imported by pkg_resources.extern (top-level), pkg_resources (top-level), pkg_resources.py31compat (top-level)
missing module named posix - imported by os (conditional, optional)
missing module named resource - imported by posix (top-level)
missing module named copy_reg - imported by cStringIO (top-level), numpy.core (conditional), cPickle (top-level), pygame (conditional)
missing module named 'pygame._view' - imported by pygame (delayed)
missing module named pygame.sdlmain_osx - imported by pygame (top-level), pygame.macosx (top-level)
missing module named OpenGL - imported by pygame (delayed)
missing module named numpy.uint32 - imported by numpy (top-level), pygame._numpysurfarray (top-level)
missing module named 'nose.plugins' - imported by numpy.testing._private.noseclasses (top-level), numpy.testing._private.nosetester (delayed)
missing module named 'nose.util' - imported by numpy.testing._private.noseclasses (top-level)
missing module named numpy.core.number - imported by numpy.core (delayed), numpy.testing._private.utils (delayed)
missing module named numpy.core.signbit - imported by numpy.core (delayed), numpy.testing._private.utils (delayed)
missing module named numpy.core.float64 - imported by numpy.core (delayed), numpy.testing._private.utils (delayed)
missing module named numpy.core.float32 - imported by numpy.core (top-level), numpy.testing._private.utils (top-level)
missing module named numpy.core.intp - imported by numpy.core (top-level), numpy.testing._private.utils (top-level), numpy.linalg.linalg (top-level)
missing module named numpy.lib.i0 - imported by numpy.lib (top-level), numpy.dual (top-level)
missing module named dummy_thread - imported by numpy.core.arrayprint (conditional, optional), cffi.lock (conditional, optional)
missing module named thread - imported by numpy.core.arrayprint (conditional, optional), cffi.lock (conditional, optional), cffi.cparser (conditional, optional)
missing module named cpickle - imported by numpy.compat.py3k (conditional)
missing module named pickle5 - imported by numpy.compat.py3k (conditional, optional)
missing module named numpy.core.integer - imported by numpy.core (top-level), numpy.fft.helper (top-level)
missing module named numpy.core.sqrt - imported by numpy.core (top-level), numpy.linalg.linalg (top-level), numpy.fft._pocketfft (top-level)
missing module named numpy.core.conjugate - imported by numpy.core (top-level), numpy.fft._pocketfft (top-level)
missing module named numpy.core.sign - imported by numpy.core (top-level), numpy.linalg.linalg (top-level)
missing module named numpy.core.divide - imported by numpy.core (top-level), numpy.linalg.linalg (top-level)
missing module named numpy.core.object_ - imported by numpy.core (top-level), numpy.linalg.linalg (top-level)
missing module named numpy.core.geterrobj - imported by numpy.core (top-level), numpy.linalg.linalg (top-level)
missing module named numpy.core.add - imported by numpy.core (top-level), numpy.linalg.linalg (top-level)
missing module named numpy.core.complexfloating - imported by numpy.core (top-level), numpy.linalg.linalg (top-level)
missing module named numpy.core.inexact - imported by numpy.core (top-level), numpy.linalg.linalg (top-level)
missing module named numpy.core.cdouble - imported by numpy.core (top-level), numpy.linalg.linalg (top-level)
missing module named numpy.core.csingle - imported by numpy.core (top-level), numpy.linalg.linalg (top-level)
missing module named numpy.core.double - imported by numpy.core (top-level), numpy.linalg.linalg (top-level)
missing module named numpy.core.single - imported by numpy.core (top-level), numpy.linalg.linalg (top-level)
missing module named future_builtins - imported by numpy.lib.npyio (conditional)
missing module named urllib2 - imported by numpy.lib._datasource (delayed, conditional)
missing module named urlparse - imported by numpy.lib._datasource (delayed, conditional)
missing module named numpy.recarray - imported by numpy (top-level), numpy.ma.mrecords (top-level)
missing module named numpy.dtype - imported by numpy (top-level), numpy.ma.mrecords (top-level), numpy.ctypeslib (top-level)
missing module named numpy.expand_dims - imported by numpy (top-level), numpy.ma.core (top-level)
missing module named numpy.array - imported by numpy (top-level), numpy.ma.core (top-level), numpy.ma.extras (top-level), numpy.ma.mrecords (top-level), numpy.ctypeslib (top-level), pygame._numpysurfarray (top-level)
missing module named numpy.bool_ - imported by numpy (top-level), numpy.ma.core (top-level), numpy.ma.mrecords (top-level)
missing module named numpy.iscomplexobj - imported by numpy (top-level), numpy.ma.core (top-level)
missing module named numpy.amin - imported by numpy (top-level), numpy.ma.core (top-level)
missing module named numpy.amax - imported by numpy (top-level), numpy.ma.core (top-level)
missing module named numpy.ndarray - imported by numpy (top-level), numpy.ma.core (top-level), numpy.ma.extras (top-level), numpy.ma.mrecords (top-level), numpy.ctypeslib (top-level), pygame._numpysurfarray (top-level)
missing module named numpy.histogramdd - imported by numpy (delayed), numpy.lib.twodim_base (delayed)
missing module named numpy.eye - imported by numpy (delayed), numpy.core.numeric (delayed)
missing module named 'pygame.movie' - imported by pygame (optional)
missing module named pygame.SRCALPHA - imported by pygame (top-level), pygame.ftfont (top-level)
missing module named Queue - imported by pygame.threads (conditional)
missing module named Py25Queue - imported by pygame.threads (conditional)
missing module named cStringIO - imported by pygame.compat (conditional), cPickle (top-level), cffi.ffiplatform (optional)

But with --onedir same problem but error not showing up.



Read more here: https://stackoverflow.com/questions/67924584/pyinstaller-exe-file-does-nothing

Content Attribution

This content was originally published by Kamil Loska at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: