I am creating a Python 3.9 game using Pygame. I want to bundle it as a .app file using py2app, but pygame needs Absolute Paths for the assets I'm using. I want to use PathLib to find the base directory, but the code I have results in the FileNotFoundError: No such file or directory.
error.
Here is a sample of my code:
import os.path
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
ASSETS_DIR = os.path.join(BASE_DIR, 'assets')
# Load images
RED_SPACE_SHIP = pygame.image.load(os.path.join(ASSETS_DIR, 'pixel_ship_red_small.png'))
GREEN_SPACE_SHIP = pygame.image.load(os.path.join(ASSETS_DIR, 'pixel_ship_green_small.png'))
BLUE_SPACE_SHIP = pygame.image.load(os.path.join(ASSETS_DIR, 'pixel_ship_blue_small.png'))
Please can someone tell me what my issue is?
I used an extra .parent
That was the issue so it was looking in the wrong directory.