0

I'm trying to create a very simple space invaders pygame for my Python class. I haven't got anywhere far yet but I keep receiving image loading errors when I try to test out the code. I am using Python 2.7 with Pycharm. This is my source code.

import pygame
from pygame.locals import *


pygame.init()
width, height = 640, 480
screen = pygame.display.set_mode((width, height))

player = pygame.image.load("spacecraft.png")

#infinite loop
while 1:
    screen.fill(0)
    screen.blit(player, (100,100))
    pygame.display.flip()
    #loop though the events
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            #if it is quit the game
            pygame.quit()
            exit()

Again this only should show a black screen with a picture of a spaceship in those coordinates. However, when I test it out the program shows this error:

libpng warning: Application built with libpng-1.6.23 but running with 1.5.4
line 9, in <module>
player = pygame.image.load("spacecraft.png")
pygame.error: Couldn't allocate memory for PNG file or incompatible PNG dll

I have tried re-installing Pygame, Python, and also tried using os to correctly path the image. The path to the image is root so I checked that off my checklist. I also downloaded libpng.1.6.16 but that didn't work either. Is there a way for me to fix this? BTW I'm not familiar with memory management. If you need any more information I will try to answer the best I can.

Thanks in advance!!

신도현
  • 13
  • 1
  • 3
  • you have to find library `libpng.1.6.23` and put in folder with `libpng.1.5.4` Or replace it. This library is not part of PyGame or Python so reinstalling nothing change - except you find `PyGame` compiled for `libpng.1.5.4` - Try http://www.pygame.org/download.shtml or http://www.lfd.uci.edu/~gohlke/pythonlibs/ – furas Nov 11 '16 at 03:11
  • meanwhile try with `.jpg` files. – furas Nov 11 '16 at 03:12
  • @furas Ah thank you!! Jpg files do work and program is running! I am still having trouble with finding libpng 1.5.4 since it downloaded with pygame through Pycharm but for now thanks! – 신도현 Nov 11 '16 at 04:01
  • libpng is C/C++ library which mostly is installed in `C:\Windows` or subfolder like. I don't use Windows (any more) so I can't check it. – furas Nov 11 '16 at 15:27

0 Answers0