Pycharm: “Cannot find reference 'load' in

2019-09-15 00:33发布

问题:

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

回答1:

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.