-->

pygame.error: File is not a Windows BMP file

2019-08-03 18:45发布

问题:

Running:
Mac OSX mountain Lion 10.8.3
Python 2.7.2
Pygame 1.9.2

I have a simple python pygame program that displays an image on the screen, this works great when I run it in my IDE. The problem comes when try to make it a standalone program using py2app I get the Error:

pygame.error: File is not a Windows BMP file

I did some research and found out that it is probably an error with pygame or SDL_image.framework so I reinstalled both and I get the same error. However, when I do use a BMP image the program works fine although I cannot use image formats such as .png or .jpg.

window.py:

import pygame,sys
from pygame.locals import *

pygame.init()
size=[700,500]
screen=pygame.display.set_mode(size)
clock=pygame.time.Clock()

img = pygame.image.load("Images/img.png") # Error generated here

# -------- Main Program Loop -----------
while True:
    # ALL EVENT PROCESSING SHOULD GO BELOW THIS COMMENT
    for event in pygame.event.get():
        if event.type == QUIT:
            isRunning = False
            pygame.quit()
            sys.exit()

    screen.blit(img,(300,300))

    pygame.display.flip()
    clock.tick(20)

If it is of any use, here is my setup.py file:

from setuptools import setup

APP = ['window.py']
DATA_FILES = [('', ['images'])]
OPTIONS = {'argv_emulation': True}

setup(
      app=APP,
      data_files=DATA_FILES,
      options={'py2app': OPTIONS},
      setup_requires=['py2app'],
      )

Problem Solution for 2.7.2:

Turns out my pygame files got or were corrupted. To solve the problem I replaced my old pygame files within the application with new pygame files. The pygame folder in the application is located at "app.app/Contents/Resources/lib/python2.7/lib-dynload". Replace the old pygame folder with this one and hopefully it will work:

https://dl.dropboxusercontent.com/u/84011326/Youtube%20files/pygame.zip

Other Solution

I downloaded python version 2.7.5 for mac and this simply fixed all errors from not being able to load the pygame mixer to being able to load jpg and png images.

回答1:

I encountered the same problem. Was able to fix it with a simple python update.

FAST SOLUTION for beginners:

  1. install Python 2.7.5

  2. Go into Applications --> Python 2.7 --> update Shell profile

  3. Python 2.7.5 should now be your default python. Run your application with that (in terminal) and it all works.

This is by far the easiest way to get around this problem. Hope this helps.



回答2:

I am a relative noob in python. Just installed python 3.3.5 and pygame 1.9.2 (as recommended) after OS upgrade. Had this issue with pygame not recognising non-BMP images, so all my previous work was not running.

After reading many similar problems here and elsewhere, I decided to roll back versions. Python 3.3.0 and pygame-1.9.2a0.win32-py3.3.msi from pygame site (http://pygame.info/downloads/) does not work.

Rolling back further to combination of last machine python 3.2.3 & pygame pygame-1.9.2a0.win32-py3.2.msi seems to work. OS Win 7. >>>pygame.image.get_extended = 1