0

Whenever I try to run my program which is,

game_folder = os.path.dirname('C:/Users/Afolabi/Downloads')
img_folder = os.path.join(game_folder, 'img')
player_img = pygame.image.load(os.path.join(img_folder, 'p1_jump.png')).convert()

It gives this,

Traceback (most recent call last):
File "C:\Users\Afolabi\AppData\Local\Programs\Python\Python36-32\Mario v.1.py", line 8, in <module>
player_img = pygame.image.load(os.path.join(img_folder, 'p1_jump.png')).convert()
pygame.error: Couldn't open C:/Users/Afolabi\img\p1_jump.png

Please what is happening and how do I fix it. From where I got this code the person uses an OS X computer.So maybe that is it? Please help.

  • 1
    First don't store your programs inside of the Python directory. Second are you using the Python36-32 beta version? :) Better download the latest version. Now to the path problem, does the directory with the image actually exist, are there any typos, and does it contain the file? You should better store the images in a subdirectory of your game and use relative paths if you ever want to share the game with others. – skrx Jul 20 '17 at 09:32
  • First of all, I don't store it in the python directory, second of all no typos, the file is there, next is please what do I do. – Afolabi Williams Jul 21 '17 at 18:09
  • Try to print this `print(os.path.isfile('C:/Users/Afolabi/img/p1_jump.png'))` (should print `True` if the file is there, otherwise `False`), and then see if it works if you pass the complete path instead of constructing it: `player_img = pygame.image.load('C:/Users/Afolabi/img/p1_jump.png').convert()`. – skrx Jul 21 '17 at 18:51

0 Answers0