0

I am learning how to use Pygame and when I am loading the assets to use in my project it gives me a FileNotFound error. The code it gives me an error at is NORMAL_BINGUS = pygame.image.load(os.path.join('assets', 'Bingus_Normal.jpg'))

The assets folder is in the same folder my code is in, and the image name is exactly the same as I typed above, so I do not know what the cause for this could be.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124

1 Answers1

0

Code may run in a different folder and it may search assets in the wrong place.

You need to create an absolute path to the folder with the code.

BASE = os.path.dirname(os.path.abspath(__file__))

And later use it to create an absolute path to every asset:

os.path.join(BASE, 'assets', 'Bingus_Normal.jpg')
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
furas
  • 119,752
  • 10
  • 94
  • 135