Pygame Error: File is not a windows BMP file

Question:

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

Asked By: LeonBrain

||

Answers:

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.

Answered By: lqhcpsgbl

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

Answered By: LeonBrain

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.

Answered By: PaulMest
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.