1. 简介

pygame 是基于对 SDL库的python 封装,提供python接口。SDL(Simple DirectMedia Layer) 是一个跨平台的游戏开发库,方便游戏开发和移植。目前最新版本SDL1.2.14. 下载地址:http://www.libsdl.org/download-1.2.php.
SDL库作者Sam Lantinga,采用C语言开发。SDL还有perl, erlang, Pango,ruby等语言的封装。

pygame 作者是Pete Shinners。

2. 下载pygame包

http://www.oschina.net/p/pygame

软件下载

或通过apt-get 直接安装。没测试。

sudo apt-get install python-pygame

如果是直接下载的,则需要手动配置如下的软件。

3. 安装SDL

我下载的是pygame-1.9.1release.tar.gz,2MB大小。解压后进入目录执行

python config.py

提示

sh: sdl-config: not found

sh: smpeg-config: not found

SDL没有安装,执行

sudo aptitude install libsdl1.2-dev

我按装时遇到缺少依赖的库,就百度,然后下载deb包、安装。

其余源码和其他平台的安装包如rpm可以访问

http://www.libsdl.org/download-1.2.php

找到。

4. 安装其他必须软件

再执行python config.py

提示

Hunting dependencies...

sh: smpeg-config: not found

WARNING: "smpeg-config" failed!

SDL : found 1.2.13

FONT : not found

IMAGE : not found

MIXER : not found

SMPEG : not found

PNG : not found

JPEG : not found

SCRAP : not found

PORTMIDI: not found

PORTTIME: not found

不要放过这些 not found,一个个搞定的。

sudo apt-get install libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl-gfx1.2-dev libsdl-net1.2-dev libsdl-sge-dev libsdl-sound1.2-dev libportmidi-dev libsmpeg-dev

其中mixer是混音库,sound是声音库,ttf是字体库,gfx,sge,image都是图形处理的。smpeg是播放mpeg电影的。midi是处理midi声音的。

安装库的时候,有些依赖可能没有,别怕怕,有百度。哈哈。

如果python没有安装开发库,也会导致pygame不能安装,比如找不到python.h 等文件

sudo apt-get install python2.6-dev

根据机器python版本安装相应的开发库。我的python是2.6.4版本,所以安装2.6的开发库。

还需安装python的numeric库,用于处理向量和数值计算,某些游戏需要。

sudo apt-get install python-numeric python-numpy python-scipy

5. 安装pygame.再次执行

sudo ./config.py

SDL : found 1.2.14

FONT : found

IMAGE : found

MIXER : found

SMPEG : found 0.4.5

PNG : found

JPEG : found

SCRAP : found

PORTMIDI: found

PORTTIME: found

执行

sudo python setup.py

成功后pygame即安装完毕。如果有问题再根据错误安装相应软件和库。

6.试用pygame

进入examples,执行

chmod +x *

./aliens.py

你就尽情的去试吧。

05-21 16:51
查看更多