12

I'm having problem following this tutorial. After I run it, an error message pops up

"ball = pygame.image.load("...) Error:File is not a Windows BMP file.

I'm on OSX 10.9.5

I highly suspect I messed up the installation for all the necessary components, and the my steps are the following when I install:

  1. Delete Python 3 and reinstall Python 2.7 32-bit version (using the .dmg)
  2. Install the pygame package using the .dmg
  3. Was asked to install X11, installed X11
  4. Open SDL framework .zip and drag and drop into a folder in Application/Library

Did I mess it up? Especially for the SDL? Please tell me the solution, thank you.

//Tried putting the image file in the same directory; saving the image file as .bmp

Sheva Kadu
  • 91
  • 9
LeonBrain
  • 347
  • 1
  • 3
  • 15

3 Answers3

1

I followed the solution here answer. Head to Macintosh HD/Library/Frameworks/..... and delete the pygame folder within and reinstall.

Community
  • 1
  • 1
LeonBrain
  • 347
  • 1
  • 3
  • 15
  • It's cool this solved your problem. It's worth noting that, according to [the pygame.image docs](http://www.pygame.org/docs/ref/image.html): "The image module is a required dependency of Pygame, but it only optionally supports any extended file formats. By default it can only load uncompressed BMP images." It's likely that your original version of Pygame wasn't built correctly. – Brad Montgomery Mar 01 '15 at 22:33
0

I saw the link and save the pic as ball.bmp (the pic is a gif format in the page) and try the code below:

import sys, pygame
pygame.init()

size = width, height = 320, 240
speed = [2, 2]
black = 0, 0, 0
screen = pygame.display.set_mode(size)

ball = pygame.image.load("ball.bmp")
ballrect = ball.get_rect()
while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT: sys.exit()

        ballrect = ballrect.move(speed)
        if ballrect.left < 0 or ballrect.right > width:
            speed[0] = -speed[0]
        if ballrect.top < 0 or ballrect.bottom > height:
            speed[1] = -speed[1]

        screen.fill(black)
        screen.blit(ball, ballrect)
        pygame.display.flip()

It works fine for me. Maybe you should save the pic as a .bmp file and try again.

lqhcpsgbl
  • 3,694
  • 3
  • 21
  • 30
  • Well, make sure the script file and the pic file are in the same path and try to install PIL packet for Python or just change the format of the pic into png... – lqhcpsgbl Jan 28 '15 at 14:16
  • Or check http://stackoverflow.com/questions/19882491/how-to-load-png-files-with-pygame-image for some info – lqhcpsgbl Jan 28 '15 at 14:17
0

This was problematic for me (even for the latest version of Pygame currently 2.1.2). I tried uninstalling and reinstalling in my pyenv virtualenv but that did not help. What ultimately helped was installing some additional system dependencies via homebrew.

$ brew install sdl2 sdl2_mixer sdl2_gfx sdl2_image sdl2_net sdl2_ttf

And after this, I uninstalled and reinstalled pygame via pip and it started working.

PaulMest
  • 12,925
  • 7
  • 53
  • 50