I´m trying to pass my game.py to an executable with auto-py-to-exe with the one file method, It fully works with the one directory method but I´m having problems with the loading of some images I think.
The thing is, I activated the debug all and first I had problems with the root files to load but I managed to make it work, you just had to pash the resource_path with the image (in this case):
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
# example of what I had to do so it got me the images right
background_img = pygame.image.load(resource_path("fondo_memory.png"))
Ok, so root files clear, all good, but then with the folder images, I added them in the additional files in the autopytoexe interface, but I think the program its not getting them right:
This is how I tried to load my pictures from the Imgs folder, adding the resource_path like with the root files:
index = 0
for filename in os.listdir():
if filename.startswith("Imgs"):
images = []
cont = 0
files = os.listdir(filename)
random.shuffle(files)
for file in files:
img = pygame.image.load(resource_path(os.path.join(filename, file)))
print(resource_path(os.path.join(filename, file)))
img.set_colorkey(WHITE)
if cont < 6:
images.append(GameImage(img))
cont += 1
game_images_dict[index] = images
index += 1
I did change it to adding the resource_path, but it still doesn´t work, the print (resource_path(os.path.join(filename, file))) gives me this:
So yeah, no idea why it doesn´t work, because I can start the game with the elements I have initialized in the root directory, but when I go to the scene where the images of the folder should be, it doesn´t show anything. I think it has to do with the loading of the images, but I might be wrong.