next up previous contents
Up: 6. USING SVM AND Previous: 6.3 Installing Java SDK   Contents

6.4 Installing PyGame

PyGame (, a gaming library for Python, is required by some example models of SVM, such as the CD Player and the MP3 Player. Hence, the users are highly recommended to install PyGame, though it is not necessary for SVM or SCC.

First, the users must download the PyGame source. It is available at:

The version that is used here is 1.6.

After download the source package (pygame-1.6.tar.gz), the users should extract it, and a directory named pygame-1.6 is created.

Before PyGame can be compiled, the users must manually install the SDL library for Cygwin. To do this, the following steps should be taken:

  1. Install Numerical Python. The source package ( Numeric-23.1.tar.gz) can be downloaded from:

    After downloading the package, extract it and a directory named Numeric-23.1 is created. Go into the directory and execute the following command:

    python install build

  2. Download the SDL binary for Win32 from the following location:

    Extract the package, and a directory named prebuilt is created.

  3. Get from any of the following locations:

    Extract the package and copy pexports.exe to /usr/local/bin.

  4. Create the following script ( in /usr/local/bin:

    mkdir -p /usr/local/lib
    for fn in "$@"
      if test -f $dest
        echo $dest already exists. Skipping ...;
        echo "$fn ===> /usr/local/lib/lib$lib.a";
        pexports.exe $lib.dll > $lib.def && dlltool --def $lib.def --dllname $lib.dll --output-lib lib$lib.a && rm $lib.def;
        mv lib$lib.a /usr/local/lib;

  5. Go to the prebuilt directory that was just generated, cd to its lib sub-directory. Execute the following command (assume /usr/local/bin is in the path): *.dll

    The script generates several SDL libraries in /usr/local/lib.

  6. Copy all the head files (*.h) in prebuilt/include into /usr/local/include/SDL. (Create it if the directory does not exist yet.)

  7. Execute the following commands in prebuilt/lib to allow the execution of the .dll files, and copy them to /usr/local/bin:

    chmod +x *.dll
    cp *.dll /usr/local/bin

  8. Go to the pygame-1.6 directory and manually create the following Setup script (it is supposed to be automatically generated by, however, does not work in Cygwin):

    #This Setup file is used by the script to configure the
    #python extensions. You will likely use the "" which will
    #build a correct Setup file for you based on your system settings.
    #If not, the format is simple enough to edit by hand. First change
    #the needed command-line flags for each dependency, then comment out
    #any unavailable optional modules in the first optional section.
    FONT = -lSDL_ttf
    IMAGE = -lSDL_image
    MIXER = -lSDL_mixer
    SMPEG = -lsmpeg
    NUMERIC = -I.
    #the following modules are optional. you will want to compile
    #everything you can, but you can ignore ones you don't have
    #dependencies for, just comment them out
    imageext src/imageext.c $(SDL) $(IMAGE)
    font src/font.c $(SDL) $(FONT)
    mixer src/mixer.c $(SDL) $(MIXER)
    mixer_music src/music.c $(SDL) $(MIXER)
    movie src/movie.c $(SDL) $(SMPEG)
    surfarray src/surfarray.c $(SDL) $(NUMERIC)
    sndarray src/sndarray.c $(SDL) $(NUMERIC) $(MIXER)
    #these modules are required for pygame to run. they only require
    #SDL as a dependency. these should not be altered
    base src/base.c $(SDL)
    cdrom src/cdrom.c $(SDL)
    constants src/constants.c $(SDL)
    display src/display.c $(SDL)
    event src/event.c $(SDL)
    key src/key.c $(SDL)
    mouse src/mouse.c $(SDL)
    rect src/rect.c $(SDL)
    rwobject src/rwobject.c $(SDL)
    surface src/surface.c src/alphablit.c $(SDL)
    surflock src/surflock.c $(SDL)
    time src/time.c $(SDL)
    joystick src/joystick.c $(SDL)
    draw src/draw.c $(SDL)
    image src/image.c $(SDL)
    transform src/transform.c src/rotozoom.c src/scale2x.c $(SDL)
    #the following are placeholders. can use them to help
    #auto-copy needed DLLs into the pygame installation folder.
    #you can simply ignore these lines under non-windows, no need to
    #comment out.
    COPYLIB_smpeg $(SDL) $(SMPEG)

    Execute the following commands to build and install PyGame (assuming that the current shell is bash):

    export LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH
    export CPATH=/usr/local/include/SDL:$CPATH
    python install build

After all these steps, PyGame should have been built for the Python that was used in the build. Try the following command to see if everything goes right:

python -c "import pygame; print pygame.__version__"

next up previous contents
Up: 6. USING SVM AND Previous: 6.3 Installing Java SDK   Contents
Thomas Huining Feng