PyGame.error in ubuntu

2024/10/7 18:23:40

I have problem with pygame and python 3 in ubuntu 12.10. When i tried load an image i got this error:

pygame.error: File is not a Windows BMP file

But in python 2.7 all works fine. I use code from http://inventwithpython.com/chapter19.html

Sorry for my poor English.

import pygame, sys, time, random
from pygame.locals import *
# set up pygame
pygame.init()
mainClock = pygame.time.Clock()
# set up the window
WINDOWWIDTH = 400
WINDOWHEIGHT = 400
windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32)
pygame.display.set_caption('Sprites and Sound')
# set up the colors
BLACK = (0, 0, 0)
# set up the block data structure
player = pygame.Rect(300, 100, 40, 40)
playerImage = pygame.image.load('player.png')
playerStretchedImage = pygame.transform.scale(playerImage, (40, 40))
foodImage = pygame.image.load('cherry.png')
foods = []
for i in range(20):foods.append(pygame.Rect(random.randint(0, WINDOWWIDTH - 20), random.randint(0, WINDOWHEIGHT - 20), 20, 20))
foodCounter = 0
NEWFOOD = 40
# set up keyboard variables
moveLeft = False
moveRight = False
moveUp = False
moveDown = False
MOVESPEED = 6
# set up music
pickUpSound = pygame.mixer.Sound('pickup.wav')
pygame.mixer.music.load('background.mid')
pygame.mixer.music.play(-1, 0.0)
musicPlaying = True
# run the game loop
while True:# check for the QUIT eventfor event in pygame.event.get():if event.type == QUIT:pygame.quit()sys.exit()if event.type == KEYDOWN:# change the keyboard variablesif event.key == K_LEFT or event.key == ord('a'):moveRight = FalsemoveLeft = Trueif event.key == K_RIGHT or event.key == ord('d'):moveLeft = FalsemoveRight = Trueif event.key == K_UP or event.key == ord('w'):moveDown = FalsemoveUp = Trueif event.key == K_DOWN or event.key == ord('s'):moveUp = FalsemoveDown = Trueif event.type == KEYUP:if event.key == K_ESCAPE:pygame.quit()sys.exit()if event.key == K_LEFT or event.key == ord('a'):moveLeft = Falseif event.key == K_RIGHT or event.key == ord('d'):moveRight = Falseif event.key == K_UP or event.key == ord('w'):moveUp = Falseif event.key == K_DOWN or event.key == ord('s'):moveDown = Falseif event.key == ord('x'):player.top = random.randint(0, WINDOWHEIGHT - player.height)player.left = random.randint(0, WINDOWWIDTH - player.width)if event.key == ord('m'):if musicPlaying:pygame.mixer.music.stop()else:pygame.mixer.music.play(-1, 0.0)musicPlaying = not musicPlayingif event.type == MOUSEBUTTONUP:foods.append(pygame.Rect(event.pos[0] - 10, event.pos[1] - 10, 20, 20))foodCounter += 1if foodCounter >= NEWFOOD:# add new foodfoodCounter = 0foods.append(pygame.Rect(random.randint(0, WINDOWWIDTH - 20), random.randint(0, WINDOWHEIGHT - 20), 20, 20))# draw the black background onto the surfacewindowSurface.fill(BLACK)# move the playerif moveDown and player.bottom < WINDOWHEIGHT:player.top += MOVESPEEDif moveUp and player.top > 0:player.top -= MOVESPEEDif moveLeft and player.left > 0:player.left -= MOVESPEEDif moveRight and player.right < WINDOWWIDTH:player.right += MOVESPEED# draw the block onto the surfacewindowSurface.blit(playerStretchedImage, player)# check if the block has intersected with any food squares.for food in foods[:]:if player.colliderect(food):foods.remove(food)player = pygame.Rect(player.left, player.top, player.width + 2, player.height + 2)playerStretchedImage = pygame.transform.scale(playerImage, (player.width, player.height))if musicPlaying:pickUpSound.play()# draw the foodfor food in foods:windowSurface.blit(foodImage, food)# draw the window onto the screenpygame.display.update()mainClock.tick(40)
Answer

The Ubuntu released repo specifically shows Python 2.7 as a dependency of PyGame 1.6.1 which is the current version in the Ubuntu Released repo. It may just be the only version of Python supported by the package.

To see this info yourself try apt-cache depends python-pygame.

https://en.xdnf.cn/q/118792.html

Related Q&A

Firebase Admin SDK with Flask throws error No module named firebase_admin

--- Question closedIt was my mistake, my uWSGI startup script switches to a different virtualenv.--- Original questionIm trying to publish push notifications from my Flask app server to Android APP. Se…

Recursive generator for change money - python

First, thanks for any help. I have this recursive code for counting ways of change from a list of coins and a given amount. I need to write a recursive generator code that presents the ways in every it…

Like button not recording the data [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar q…

Python, Pygame, Image manipulation: Restretch a loaded png, to be the texture for an isometric Tile

Im a 17 year old programmer, trying to program an isometric game in python, with pygame. After finishing a tile engine, working with not good looking, gimp-drawn PNGs, I wondered, if it would be possib…

TypeError: list object is not callable [duplicate]

This question already has answers here:TypeError: list object is not callable while trying to access a list(9 answers)Closed 10 years ago.I cant find the problem im facing... this is exactly what the …

Tokenise text and create more rows for each row in dataframe

I want to do this with python and pandas.Lets suppose that I have the following:file_id text 1 I am the first document. I am a nice document. 2 I am the second document. I am an even …

Is the example of the descriptor protocol in the Python 3.6 documentation incorrect?

I am new to Python and looking through its documentation I encountered the following example of the descriptor protocol that in my opinion is incorrect. .It looks like class IntField:def __get__(self, …

How to clean a string to get value_counts for words of interest by date?

I have the following data generated from a groupby(Datetime) and value_counts()Datetime 0 01/01/2020 Paul 803 2 01/02/2020 Paul 210982360967 1 …

Folium - Map doesnt appear

I try to get map through Folium but only thing I can see is marker on blank page. Id like to know where is problem lies, in explorer or coding. map.py import foliummap = folium.Map(location = [46.20, 6…

python tkinter exe built with cx_Freeze for windows wont show GUI

PROBLEM SOLVED. the issue was with jaraco module, that i used for clipboard manipulation, i used pyperclip instead.I made a python app with tkinter that works fine, but I wanted to make an exe from it …