0

I have a problem I'm working in Pycharm with Pygames and when I try to pygame.image.load() it doesn't work and keep telling me that it cannot find 'load' in image.py. I redownloaded the pygame package and it still doesn't work. Please help me.

Pycharm reports: Cannot find reference 'load' in 'image.py', when using pygame.image.load(). The code breaks when trying to execute this command.

import pygame

pygame.init()

surface = pygame.display.set_mode((1200, 720))
my_image = pygame.image.load('maxresdefault.bmp')

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

    surface.fill((188, 22, 22)
    surface.blit(my_image, (0, 0))

    pygame.display.update()

pygame.quit()

After redownloading the Pygame package, the issue persists.

Code

Error text

You
  • 11
  • 1
  • 1
  • 1
    Please **[edit]** your post and show the actual code and error messages as text instead of screenshots. Others can't copy and paste from your images. [See here](https://meta.stackoverflow.com/a/285557/1402846) for details. Thank you. – Pang May 05 '17 at 03:43
  • Pycharm mistakenly warns that `pygame.image.load` cannot be found, but it can. Try loading a png image instead, because pygame can only load a limited amount of formats. – Ted Klein Bergman May 05 '17 at 15:31
  • After looking through the image.py code in Pycharm, I've found that it imports `load()` from another file: `from pygame.imageext import load, load_extended, save_extended`. There is no method named `load`in imageext.py, at least not one that Pycharm shows. [Pygame.image](https://www.pygame.org/docs/ref/image.html) – Andreas is moving to Codidact Jul 28 '17 at 12:42

1 Answers1

0

PyCharm seems to have problems referencing load but it works fine. There are 2 separate issues here: The load error (which can be ignored as there doesn't seem to be any way around it, and PyGame works just fine), but secondly, and more importantly, there is a problem with your image file itself. Is it in the same directory as your script? .bmp is the standard format so that shouldn't be an issue. If it's in the right directory, and the name is correct, try converting it to a .png or .jpg image.

Jayce
  • 539
  • 6
  • 21