0

I am trying to make a game with Python 3.9.13 when i try to load a file for example like this:

sky_ = pygame.image.load('/graphics/Sky.png').convert_alpha()

the python file is located right behind the graphics folder so python should look where the python file is located but it looks in C:/Users/IAMAUSER

it only works if i have it like this:

sky_ = pygame.image.load('C:/Users/IAMAUSER/OneDrive/Desktop/Pro/Pygame/graphics/Sky.png').convert_alpha()

i hope i explained it well enough

i tried doing it like this but it still didnt work:

sky_ = pygame.image.load('../graphics/Sky.png').convert_alpha()

i also tried like this:

sky_ = pygame.image.load('C:\..\Game\graphics\Sky.png').convert_alpha()

it was expecting for that to work but it did not

  • You have to set the working directory. Add the following 2 lines at the begin of your code: 1. `import os` 2. `os.chdir(os.path.dirname(os.path.abspath(__file__)))`. Also see [Could not open resource file, pygame error: "FileNotFoundError: No such file or directory."](https://stackoverflow.com/questions/58177145/could-not-open-resource-file-pygame-error-filenotfounderror-no-such-file-or) – Rabbid76 Jan 14 '23 at 11:07

0 Answers0