[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Unix building Info and compiling in Red Hat, update



Hello to all,
The previous week I spend some time to install pygame from source to a machine
and I thought it will be nice idea to add the things I've learned in pygames documentation.

So in the attachment I have added some more details about compiling pygame from source
(Unix Building Info)

Also, I edited the wiki page on the site about Red Hat compilation. (As Fedora is my distribution
of choice the last couple of years)

Do you think that it will be nice to merge the changes I did into install.txt and install.html?
I'm also thinking it would be nice if you could add an subsection to Compilation section in pygames wiki
with title "Unix Building" to have my document added there.

Regards, Panos.
Compiling and installing pygame is handled by Python's distutils.
Pygame also comes with some scripts to automatically configure the
flags needed to build pygame. Use the "setup.py" script to start the
installation.

The first time you run the setup script, it will call the "config.py"
script. This will build a "Setup" file which stores all the
information needed to compile. The "config.py" will do a good job of
detecting what dependencies are available and where they are located.
If it isn't perfect, it is easy to build your own, or edit the created
"Setup" text file. This "Setup" file is a simple Makefile-like text
file. It defines variables needed to use each dependency, and then
enables all the pygame modules with found dependencies. If you have
trouble compiling, you should be able to easily fix any problems
inside the "Setup" file.

Unix Compiling Info
Compiling from linux shouldn't give you any problems. One thing you
must keep in mind is that most linux RPM packages separate the actual
library from the "dev" files needed to compile. To build you will need
to make sure the packages like "SDL-dev" are installed.

You can check to see if SDL is ready to be built from by running the
command sdl-config and seeing if it is found. If the sdl-config script
is not on the path (or you have more than one?) Set the environment
variable SDL_CONFIG to its location. (SDL_CONFIG=/path/to/sdl/sdl-config)


Sometimes you will have the SDL libraries installed in once location,
and the other SDL libraries in another. This tricks the pygame config
scripts, but you can help it out by setting the environment LOCALBASE
to a path prefix where the other libraries are. The common case for
this is SDL installed in /usr and other SDL libs installed in
/usr/local. The command for this situation is "LOCALBASE=/usr/local
python setup.py install".

If you have all the required libraries and their development versions
installed in your system you should follow the above commands. They
should work on any Unix system.

Building:
After downloading and unpacking the release tarball:

$ tar xvf pygame-1.9.1release.tar.gz
$ cd pygame-1.9.1release 

Running the "setup.py" script will call distutils to build and install
the pygame package. Distutils actually supports a wide variety of
compile and install options. running "python setup.py help" will start
to show you the different options available. You can change many
things like install locations, compiler to use, and more. Calling the
"setup.py" script with no arguments and it will just ask you if you
want the default flags needed to compile and install.

# Run the build command that should build for you the pygame module:
$ python setup.py build

After building, pygame is ready for install.

If you have root privileges (either by log-in as the root user of by using sudo)
and you want to install pygame for Python in your system for all users, just do:

$ python setup.py install

This will install the pygame package at standard location 
prefix/lib/pythonX.X/site-packages.

If you do not have root privileges or you want to install pygame for Python only 
for your user, you have two options depending on the target Python version.

#For Python 2.6 and up:
$ python setup.py install --user

#For Python 2.5 and below:
$ python setup.py install --home=$HOME

Then, add $HOME/lib/python or $HOME/lib64/python to your PYTHONPATH environment variable.

Another situation comes when you wish to have all the required libraries 
in your user scope (NOT so recommended) and you want to install pygame 
only for your user and not for the whole system, for example when you 
have an account and no root access or your distribution has old dev packages 
in it's repositories. Then, you should be aware of the things below.

First of all you have to download and compile/install every library 
Setup file is mentioning. (Setup file is in the folder of pygames source)

SDL, FONT, IMAGE, MIXER (libsdl-font, libsdl-image etc)
SMPEG 
PNG 
JPEG
SCRAP 
PORTMIDI 
PORTTIME
AVFORMAT
SWSCALE
FREETYPE

Note: In Setup file there are some libraries that they are optional
You will propabley want to compile everything you can, but you can 
ignore ones of those you don't have dependencies for, just comment 
them out.

The commands to untar and install every library in your $HOME will be:
tar xvf library_name.tar.gz
cd library_name
./configure --prefix=$HOME/local_folder
make
make install

Note: Some libraries require some other to compile. You should update 
LD_LIBRARY_PATH env variable to point your linker to your local_folder
where your freshly installed libraries are. Something like that will do

$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/user/local_folder

After compiling every C library you can install pygame as above:

# Run the build command that should build for you the pygame module:
$ python setup.py build

# For Python 2.6 and up:
$ python setup.py install --user

# For Python 2.5 and below:
$ python setup.py install --home=$HOME

Then, add $HOME/lib/python or $HOME/lib64/python to your PYTHONPATH 
environment variable.