一 说明:
pygame is a library for python 3d
pygame是python的游戏开发包。
二 前提准备
pygame的安装前提是:
python2.6+ 和 SDL, 可以使用如下安装方式(Linux下)
$ yum install python2.6* SDL SDL*
$ yum install python-image* # PIL: python image 处理模块
需要使用python源代码文件
$yum install python-devel*
需要使用gd,gd-devel*
$yum install gd, gd-devel
下载pygame:
http://pygame.org/ftp/pygame-1.9.1release.tar.gz
下载PyOpenGL,用于图像幀处理:
http://pypi.python.org/packages/source/P/PyOpenGL/PyOpenGL-3.0.1.tar.gz#md5=cdf03284f24279b8d9914bb680a37b5e三 安装
1. 首先安装PyOpenGL
$ tar zxvf PyOpenGL-3.0.1.tar.gz
$ cd PyOpenGL-3.0.1
$ python setup.py install
2. 其次安装 pygame
-> 解压
$ tar zxvf pygame-1.9.1release.tar.gz
$ cd pygame-19.1release/
-> 生成配置文件
$ python config.py
$ vim setup.in
修改配置文件setup.in中的以下项目:
EXTRABASE =
SDL = -I/usr/include/SDL -L/usr/lib -I/usr/include/SDL -D_REENTRANT -L/usr/lib $FONT = -lSDL_ttf
IMAGE = -lSDL_image
MIXER = -lSDL_mixer
SMPEG = -lsmpeg
(...)
imageext src/imageext.c $(SDL) $(IMAGE)
(...)
image src/image.c $(SDL)
然后编译安装:
$ python setup.py install
四 测试
在终端中输入python,进入python交互环境,然后输入import pygame,如果没有错误(没有任何输出),表示安装正确了。
五 注意
non Windows BMP images
是由于pygame.image模块没有被加载到pygame中来。you can build the pygame.image module with or without the SDL_image library. when you don't use SDL_image, you only get support for loading BMP images. this is definitely the problem here, not finding the SDL_image support. you can test if pygame.image has the SDL_image support by calling pygame.image.get_extended(), which will return a nonzero value if you can load more then just BMP. From the Build file: