Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
More pygame errors
#1
Attempting to help my son.
I cannot find the error or a reason

Extract
import png, os, pygame
pygame.init()

win = pygame.display.set_mode((1200,900))

pygame.display.set_caption("First Game")

WalkRight = pygame.image.load(os.path.join('Red_Knight_Right.png'))
WalkLeft = pygame.image.load(os.path.join('Red_Knight_left.png'))
bg = pygame.image.load(os.path.join('game background.png'))
char = pygame.image.load(os.path.join('Red Knight.png'))
Stab_left = pygame.image.load(os.path.join('Red_Knight_stab_Left.png'))

x = 500
y = 410
#varibles 
width = 40
height = 60
vel = 10
isJump = False
jumpcount = 10
left = False
right = False
Stab_left = False


def redrawGameWindow():
    
    win.blit(bg, (0,0))
    
  
    if left:
            win.blit(WalkLeft, (x,y))
            
    elif right:
            win.blit(WalkRight, (x,y))

    elif Stableft:
        win.blit(Stab_left)
 
Error:
pygame 1.9.4 Hello from the pygame community. https://www.pygame.org/contribute.html Traceback (most recent call last): File "C:\Users\******\Downloads\python_game_resourses\knight_game_combat_testing_not.py", line 8, in <module> WalkRight = pygame.image.load(os.path.join('Red_Knight_Right.png')) pygame.error: Couldn't open Red_Knight_Right.png
the image files are located in the same directory as the py file (C:\Users\******\Downloads\python_game_resourses\knight_game_combat_testing_not.py)
I have also attempted the code as follow:

WalkRight = pygame.image.load('Red_Knight_Right.png')
WalkLeft = pygame.image.load('Red_Knight_left.png')
bg = pygame.image.load('game background.png')
char = pygame.image.load('Red Knight.png')
Stab_left = pygame.image.load('Red_Knight_stab_Left')

Same result

I also attempted with .convert()


Why is it not picking it up ?

I have read the previous post on this topic and attempted all suggestions. Wall
Reply
#2
tldr; pygame can't find your image in the place you said it would be

the path of the file that is causing the problem is
C:\Users\******\Downloads\python_game_resourses\knight_game_combat_testing_not.py. The way you have it with pygame loading and no second argument in os.path.join, you are loading the image in the same directory
C:\Users\******\Downloads\python_game_resourses\. I am not sure if this is where you actually have the image or not?

I am also not sure why you are using os.path.join as you are not joining any paths at all.
Recommended Tutorials:
Reply
#3
Quote:C:\Users\******\Downloads\python_game_resourses\. I am not sure if this is where you actually have the image or not?

The images are in the same directory as the .py module
Reply
#4
sorry i didnt read the text in between code snippets.

you can try os.path.abspath instead
what is png module?
Quote:
import png
Recommended Tutorials:
Reply
#5
import png
I though reading https://www.pygame.org/docs/ref/image.html default support is bmp
That I had a problem with unsupported image files and installed pypng module according to docs this is to load that module.


This is not required as this is not the problem so can be removed
Reply
#6
What method did you use to install pygame?
I have only had problems like that if i compiled pygame without the proper dependencies. You should not need an extra module to handle png images in pygame.
Recommended Tutorials:
Reply
#7
Also is this file you are loading the images, your root file you are executing? IF this is a module imported to another file, and the images are in the same directory as this module, then it is going to fail. Example here (very last paragraph).
Recommended Tutorials:
Reply
#8
Quote:What method did you use to install pygame?
I have only had problems like that if i compiled pygame without the proper dependencies. You should not need an extra module to handle png images in pygame.

I used command line install :

python -m pip install -U pygame --user

I first had to update pip though

python install pip --update (if I recall the exact command correctly)
Reply
#9
(Jan-02-2019, 08:38 PM)PyEH Wrote: That I had a problem with unsupported image files and installed pypng module according to docs this is to load that module.


This is not required as this is not the problem so can be removed

(Jan-02-2019, 09:09 PM)PyEH Wrote: python -m pip install -U pygame --user

yes pygame should be able to handle that without anything additional.

Is the file loading the images the root file that you are executing directly?
Recommended Tutorials:
Reply
#10
Quote:Also is this file you are loading the images, your root file you are executing? IF this is a module imported to another file, and the images are in the same directory as this module, then it is going to fail.

I believe this is a flat directory structure.
I cannot see any root files as there are only the 2 .py files in that directory.
I will need to see if there is a full app and get the full tree structure, although I do not believe this is the case (they are learning so I think he will keep it simple)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pygame*import pygame ImportError: No module named pygame CASPERHANISCH 1 9,707 Jun-05-2017, 09:50 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020