Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pygame image load error
#1
Hi Im new to pygame and Coding in general And I just started a tutorial and Whenever I try and load my png images and I run the code i shows up as an error here is my code
import pygame

from pygame.locals import *

pygame.init()

screen_width = 800
screen_height = 600

screen = pygame.display.set_mode((screen_width,screen_height))
pygame.display.set_caption('Platformer')

#load images

bg_img = pygame.image.load("img/sky.png")


run = True
while run:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    screen.blit(bg_img, (0,0))

    pygame.display.update()

pygame.quit()
Whenever I try and do This It come up as an Error such as this

Error:
FileNotFoundError: No file 'img/sky.png' found in working directory 'C:\Users\yeg20\OneDrive\Desktop\workspace'.
Could anyone tell me why this is happening and how to fix it?
Larz60+ write Oct-12-2022, 02:19 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.

Also, when posting errors, paste the complete unaltered error traceback (error message) as it contains valuable debugging information.
Reply
#2
Your program is trying to open a file named 'C:\Users\yeg20\OneDrive\Desktop\workspace\img/sky.png'. The file does not exist.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Photo image error pyc0de 2 292 Mar-23-2024, 06:20 PM
Last Post: pyc0de
  error "cannot identify image file" part way through running hatflyer 0 683 Nov-02-2023, 11:45 PM
Last Post: hatflyer
  unable to load an image with C (Cython) HLD202 0 1,321 Jan-13-2022, 09:16 PM
Last Post: HLD202
  How to open/load image .tiff files > 2 GB ? hobbyist 1 2,472 Aug-19-2021, 12:50 AM
Last Post: Larz60+
  ERROR: Cannot load plugin dbwest1 0 1,680 Sep-15-2020, 04:28 PM
Last Post: dbwest1
  python-resize-image unicode decode error Pedroski55 3 3,501 Apr-21-2020, 10:56 AM
Last Post: Pedroski55
  Error when executing pytesseract to get the text from image bvdinesh 3 17,948 Oct-19-2019, 05:01 PM
Last Post: cwco00
  pygame.error: /etc/timidity.cfg: No such file or directory lsepolis123 3 4,332 Aug-23-2019, 07:53 AM
Last Post: lsepolis123
  Unknown error in pygame :( TheDovah77 1 2,881 Apr-14-2019, 10:22 PM
Last Post: metulburr
  Fatal Python error: Py_Initialize: unable to load the file system codec ecg1g15 0 3,584 Feb-12-2019, 12:16 PM
Last Post: ecg1g15

Forum Jump:

User Panel Messages

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