0

Title, I just finished my first pygame project which Is a very simple game with a main menu module and a main game module, they both run perfectly when I run them from sublime.

I tried using py2app to share this game with some friends, after installing py2app this is what I did in my terminal:

py2applet --make-setup MainMenu.py # (this module imports the main game module)

then I edited my setup.py file to include all my python files like images, sounds and fonts (this is the setup.py file):

"""
This is a setup.py script generated by py2applet

Usage:
    python setup.py py2app
"""

from setuptools import setup

APP = ['MainMenu.py']

DATA_FILES = ['MySprite/Shoot/1.png','MySprite/Shoot/2.png',
'MySprite/Go/1.png','MySprite/Go/2.png','MySprite/Go/3.png','MySprite/Go/4.png','MySprite/Go/5.png','MySprite/Go/6.png','MySprite/Go/7.png','MySprite/Go/8.png',
'go_1.png','go_2.png','go_3.png','go_4.png','go_5.png','go_6.png','go_7.png','go_8.png','go_9.png','go_10.png','go_1L.png','go_2L.png','go_3L.png','go_4L.png','go_5L.png','go_6L.png','go_7L.png','go_8L.png','go_9L.png','go_10L.png','HomeScreen.png','icon.png','Bullet.png','SkyNight.png','GamePlatform.png','Heart.png','Starjedi.ttf','Chernobyl.ttf',
'MainMenu.wav','Fireball.wav','background.wav','Jump.wav','Zombie.wav','Hit.wav']



OPTIONS = {}

setup(
    app = APP,
    data_files = DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

Then back to my terminal:

rm -rf build dist

then:

python setup.py py2app -A 

which gave me an error so I changed it to python3 and it created a "build" and a "dist" folders, I tried opening the app inside the "dist" folder but it gave me an error and asked me to terminate or open the console, I right clicked on it and pressed show package options --> contents --> MacOs and pressed the file which opened another terminal with the error:

screen_home = pygame.image.load('HomeScreen.png')
FileNotFoundError: No such file or directory.

Both modules run perfectly from sublime, Im out of ideas and I tried googling the problem and I can't find a solution, Im new at this so I apologize if the solution was obvious or it was a dumb question and id appreciate any help.

Ahmed Mahmoud
  • 39
  • 2
  • 7

1 Answers1

0

I don't have a real answer but a few things to try and check:

  1. We need to review a few things in the two lines, sometimes the setup.py requires to have the full path where each file is located, it is the right way, otherwise the setup.py will not find where are those images and it won't be able to include them into the final package, Are all those files in the same folder?, even if they are, try to add the full path for each file (jbsidis should be replaced by your username):

    import os APP = ['/home/jbsidis/Escritorio/MainMenu.py']

    if os.path.isfile(APP[0])==True: print("the MainMenu.py file it does exists")

    DATA_FILES = ['/home/jbsidis/Escritorio/MySprite/Shoot/1.png','/home/jbsidis/Escritorio/MySprite/Shoot/2.png','/home/jbsidis/Escritorio/MySprite/Go/1.png','/home/jbsidis/Escritorio/MySprite/Go/2.png','/home/jbsidis/Escritorio/MySprite/Go/3.png','/home/jbsidis/Escritorio/MySprite/Go/4.png','/home/jbsidis/Escritorio/MySprite/Go/5.png','/home/jbsidis/Escritorio/MySprite/Go/6.png','/home/jbsidis/Escritorio/MySprite/Go/7.png','/home/jbsidis/Escritorio/MySprite/Go/8.png','/home/jbsidis/Escritorio/go_1.png','/home/jbsidis/Escritorio/go_2.png','/home/jbsidis/Escritorio/go_3.png','/home/jbsidis/Escritorio/go_4.png','/home/jbsidis/Escritorio/go_5.png','/home/jbsidis/Escritorio/go_6.png','/home/jbsidis/Escritorio/go_7.png','/home/jbsidis/Escritorio/go_8.png','/home/jbsidis/Escritorio/go_9.png','/home/jbsidis/Escritorio/go_10.png','/home/jbsidis/Escritorio/go_1L.png','/home/jbsidis/Escritorio/go_2L.png','/home/jbsidis/Escritorio/go_3L.png','/home/jbsidis/Escritorio/go_4L.png','/home/jbsidis/Escritorio/go_5L.png','/home/jbsidis/Escritorio/go_6L.png','/home/jbsidis/Escritorio/go_7L.png','/home/jbsidis/Escritorio/go_8L.png','/home/jbsidis/Escritorio/go_9L.png','/home/jbsidis/Escritorio/go_10L.png','/home/jbsidis/Escritorio/HomeScreen.png','/home/jbsidis/Escritorio/icon.png','/home/jbsidis/Escritorio/Bullet.png','/home/jbsidis/Escritorio/SkyNight.png','/home/jbsidis/Escritorio/GamePlatform.png','/home/jbsidis/Escritorio/Heart.png','/home/jbsidis/Escritorio/Starjedi.ttf','/home/jbsidis/Escritorio/Chernobyl.ttf','/home/jbsidis/Escritorio/MainMenu.wav','/home/jbsidis/Escritorio/Fireball.wav','/home/jbsidis/Escritorio/background.wav','/home/jbsidis/Escritorio/Jump.wav','/home/jbsidis/Escritorio/Zombie.wav','/home/jbsidis/Escritorio/Hit.wav']

    for x in DATA_FILES: if os.path.isfile(x)==True: print("the "+str(x)+" file it does exists") else: print("the "+str(x)+" DOES NOT Exists in that location and that's why you got the error with your setup.py")

Here is the image in my case, my folders don't have those files, so the result is:

enter image description here

  • I just fixed the error by making a copy of the game directory and removing all sub directories and leaving the images, fonts, sounds..etc lying around in the parent directory instead, then I went back to setup.py and fixed all the paths "Imgs/HomeScreen.png" --> "HomeScreen.png", im not sure why it worked but it finally did, thanks though I was out of ideas – Ahmed Mahmoud Aug 22 '21 at 01:47