0

I am trying to use images in my pygame game and whenever I run the code, it comes up with FileNotFoundError. The file with the images is in the same folder as my main code and the name is correct.

I have tried this:

pieces = {'p': pygame.image.load('bp.png').convert(),
          'n': pygame.image.load('bN.png').convert(),
          'b': pygame.image.load('bB.png').convert(),
          'r': pygame.image.load('bR.png').convert(),
          'q': pygame.image.load('bQ.png').convert(),
          'k': pygame.image.load('bK.png').convert(),
          'P': pygame.image.load('wp.png').convert(),
          'N': pygame.image.load('wK.png').convert(),
          'B': pygame.image.load('wB.png').convert(),
          'R': pygame.image.load('wR.png').convert(),
          'Q': pygame.image.load('wQ.png').convert(),
          'K': pygame.image.load('wK.png').convert(),
      
      }

and it returns

FileNotFoundError: No file 'bp.png' found in working directory '

hrh
  • 1
  • You have to set the working directory: `import os` `os.chdir(os.path.dirname(os.path.abspath(__file__)))` (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 31 '23 at 18:08
  • do I just copy and paste that? – hrh Jan 31 '23 at 18:35

0 Answers0