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

6.4 Installing PyGame

PyGame (http://www.pygame.org/), 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:

http://www.pygame.org/download.shtml

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:

    http://sourceforge.net/projects/numpy/

    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 setup.py install build
    

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

    http://www.pygame.org/ftp/win32-dependencies.zip

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

  3. Get pexports-0.43.zip from any of the following locations:

    http://www.is.lg.ua/ftp/gnuwin32/altbinutils/pexports-0.43.zip
    http://www.emmestech.com/software/cygwin/pexports-0.43/pexports-0.43.zip

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

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

    #!/bin/sh
    
    mkdir -p /usr/local/lib
    for fn in "$@"
    do
      lib=${fn%%.dll};
      dest=/usr/local/lib/lib$lib.a
      if test -f $dest
      then
        echo $dest already exists. Skipping ...;
      else
        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;
      fi;
    done
    

  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):

    dll2a.sh *.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 config.py, however, config.py does not work in Cygwin):

    #This Setup file is used by the setup.py script to configure the
    #python extensions. You will likely use the "config.py" 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.
    
    
    SDL = -I/NEED_INC_PATH_FIX -L/NEED_LIB_PATH_FIX -lSDL
    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. setup.py 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 setup.py 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
2004-04-05