pygame.error:文件不是Windows BMP文件 [英] pygame.error: File is not a Windows BMP file

查看:892
本文介绍了pygame.error:文件不是Windows BMP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行:
Mac OSX Mountain Lion 10.8.3
Python 2.7.2
Pygame 1.9.2

Running:
Mac OSX mountain Lion 10.8.3
Python 2.7.2
Pygame 1.9.2

我有一个简单的python pygame程序,可以在屏幕上显示图像,当我在IDE中运行该图像时,效果很好.当尝试使用py2app使它成为独立程序时出现问题,我得到了错误:

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:文件不是Windows BMP文件

我进行了一些研究,发现pygame或SDL_image.framework可能是错误,因此我重新安装了两者,并得到了相同的错误.但是,当我确实使用BMP图像时,尽管我不能使用.png或.jpg之类的图像格式,但该程序仍能正常运行.

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)

如果有用,这是我的 setup.py 文件:

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'],
      )

2.7.2的问题解决方案:

结果是我的pygame文件损坏了.为了解决该问题,我用新的pygame文件替换了应用程序中的旧pygame文件.应用程序中的pygame文件夹位于"app.app/Contents/Resources/lib/python2.7/lib-dynload".用这个文件夹替换旧的pygame文件夹,并希望它可以工作:

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

其他解决方案

我下载了适用于Mac的python 2.7.5版本,这可以修复所有错误,从无法加载pygame混合器到能够加载jpg和png图像.

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.

推荐答案

我是python中的相对菜鸟.操作系统升级后,刚刚安装了python 3.3.5和pygame 1.9.2(根据建议). pygame遇到无法识别非BMP图像的问题,因此我以前的所有工作都没有运行.

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.

在阅读了这里和其他地方的许多类似问题之后,我决定回滚版本. pygame网站上的Python 3.3.0和pygame-1.9.2a0.win32-py3.3.msi( http://pygame. info/downloads/)无效.

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.

进一步回滚到最后一个机器python 3.2.3&的组合pygame pygame-1.9.2a0.win32-py3.2.msi似乎可以工作. OS Win7.>>> pygame.image.get_extended = 1

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

这篇关于pygame.error:文件不是Windows BMP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆