Core classes/modules:

Advanced:

Experimental/Broken:

Warning

Install Pygame with Wheels (.whl files)

pip is included with python from Python 2.7.9+ and Python 3.4+. So if you have older than these you have to install pip. Change <FILE.whl> to the path and name of the wheel for your python version that you downloaded. Navigate to your python directory and execute the following command.

or naviagate to your python lcoation and go into Scripts directory where pip is and type

Lets assume that you did a custom installtion and installed python at the location of C:\PythonXX. This is the default location for python3.4 and lower, but since python3.5 the default location has been at C:\Users\USERNAME\AppData\Local\Programs\Python\PythonXX-XX However to even access your AppData directory on Windows, you have to change settings to show hidden directories and files in control panel -> File Explorer Options -> View -> Hidden files and folders -> check yes and then apply changes. You can bypass this just by changing the default install location of python within the install wizard by choosing custom install and typing a new install path. C:\Python35-32 for example.

open C:\Python35-32\python.exe and type

If you get a >>> prompt with no errors then you installed pygame correctly and it is working. If you get errors you most likely downloaded the incorrect wheel file for you python installation. If you still have problems post your error and python info on reddit

Problem installing wheels?

Pip says it needs to be updated

pip may or may not give a warning saying there is a newer pip you can install. However this is just a warning. Pygame should of installed correctly even with an old pip. Open a python interpreter and test if pygame can be imported without an error.

Pip is just a PyPi package like any other, you can use it to upgrade itself the way you would any other package.

Bypassing pip by copying pygame files to your python

If you are really having trouble with pip. You can just simply copy the pygame files over to your python installation. If you downloaded the incorrect wheel this will also fail. Since windows cannot extract a wheel file all you need to do is change the wheel extension to zip instead. Extract it. It will extract 3 directories, pygame, pygame***.data, and pygame***.dist-info. The stars are where the version and bit type are. Go into pygame***.data directory and copy headers directory over to your python's include directory. So in the end, you should have C:\PythonXX\include\headers. Now rename that headers directory to "pygame". (C: \PythonXX\include\pygame) Now go back to you extracted directories from the wheel. Copy both the pygame and pygame***.dist-info directories over to pythons's Lib/site-packages directory. So these two directories will be placed into C:\PythonXX\Lib\site-packages\. (C:\PythonXX\Lib\site-packages\pygame and C:\PythonXX\Lib\site-packages\pygame***.dist-info) Now attempt to import pygame and see if was installed correctly.

Note this directory is based on the fact that python was installed at the location C:\PythonXX. Python3.4 defaults to this location whereas python3.5 and greater default to other location. You can find this location by opening a python interpreter and executing the line

Install latest Pygame with Mercurial

Install Mercurial on your platform. The first code box below is the method for Ubuntu Linux. Mercurial binaries for your platform can be found here.

Install pygame dependecies. The below example is for Ubuntu linux only.

Download Pygame by cloning the most up to date repo with Mercurial (hg). Execute the following on your command prompt/terminal.

execute the following commands

The python you execute on this code box above is the python that gets pygame installed to it. So if you want it installed to python3.x, make sure that you use python3 (Ubuntu Linux). If you get errors here you may not have a dependency installed. If you still have problems, post in the forums.

Confirm that pygame was successfully installed on your system by going to a terminal (Ubuntu Linux/Mac) or command prompt (Windows) and starting up a python interactive prompt and trying ot import pygame

The fact that a second prompt >>> came up means pygame was imported successfully. One note to mention is do not name your python scripts pygame.py as you will be importing your script instead of pygame.

This method installs the latest bitbucket repo, including its last merge. So it the best way to get the latest pygame as they add bug-fixes, but that could also be a method of obtaining an untracked bug.

BitBucket Releases

If this fails, you can try to download a release instead. This includes msi easy installers for Windows and zips. Extract the zip and change directory into it, and execute setup.py install command as said before.

Pygame Installation

Python can be built from source, but the easiest way is to get a binary package for your type of system and version of Python. This document will give you information on either type of installation.

Windows Binary Installer

This is probably the most popular method of installation. If you are running on windows, it is highly recommended you use this form of installing. The installers come with with nearly everything you need and have an easy point and click installers.

The first thing you will need is an installation of Python. Python binary installers make it easy to get this done. Pygame binaries usually come for the latest 2 releases of Python, so you'll want to be fairly up to date.

Once that is in place, you want to download the appropriate windows binary. From the pygame downloads page you can find the .EXE file you need. This will automatically install all of pygame and all the SDL dependencies. The windows binaries have filenames like this: "pygame-1.8.0release.win32-py2.5.msi". This would be the installer for pygame version 1.8.0, for Python version 2.5. You shouldn't have trouble finding the correct binary from the "Windows" section of the download page. http://www.pygame.org/download.shtml.

You will also probably want to install the windows documentation and installation package. This will add easy links to the different documentation and games that come with pygame. The installer for this is found next to the other windows binary downloads. The filename looks like this: "pygame-docs-1.8.0.exe". And this would install the documentation and examples for pygame-1.8.0

One other thing the windows binaries are missing is the Numeric or numpy Python packages. You can easily install this separately and it will allow you to use the pygame "surfarray" module. This module is optional, so there is no need to do this. A Numeric for Windows python 2.5 can be found on the download page: http://www.pygame.org/download.shtml. There are older binary installers from the Numeric download page. http://sourceforge.net/project/showfiles.php?group_id=1369.

PixelArray, which is built into pygame 1.8+, and is usually quite a lot faster is the recommended array implementation to use. Numpy is newer than Numeric, however both are not entirely compatible.


Unix Binary Packages

For many unix systems, the easiest way to install pygame is from source. Still, there are binary packages available for different distributions.

There are several binary RPM packages for linux machines. These are actually a little bit of work to install, since you will also need several RPM packages for the dependencies. There is a good chance your linux distribution came with the needed dependencies (like Python and SDL). There are binary RPMs available from the website for each dependency.

For debian systems, pygame is actively maintained in the debian archives. Visit the debian pygame page for more information. http://packages.qa.debian.org/p/pygame.html

FreeBSD also has an active pygame package. While techinicaly it isn't binary, it is automatically built and installed by the ports manager. See the FreeBSD package page for more information. http://www.freebsdports.info/ports/devel/py-game.html

Gentoo has a builtin package for pygame. This is compiled for your system as it installs, similar to BSD, http://packages.gentoo.org/package/dev-python/pygame


Mac OS X Binaries

For Mac OS X 10.3 and above, binary packages are available from http://www.pygame.org/download.shtml

This package includes almost of the dependencies required for pygame (SDL, SDL_image, etc.), but you need PyObjC 1.2 or later, and may also want to get Numeric, numpy and PyOpenGL. A PyObjC 1.4 installer is also made available on the download page.

If you want to use the Apple system python, you will need to compile from source at this time - since most people prefer to leave the system python alone, and use the python downloaded from python.org. See http://pygame.org/wiki/MacCompile for current instructions for compiling from source on Mac OSX.

pygame is also available from the fink, and macports distributions.

To build self-contained pygame applications, you should use py2app. There is an example in: /Developer/Python/pygame/Examples/macosx/aliens_app_example




Installing From Source

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.

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.

Windows Compiling Info

You can compile pygame on windows with mingw (gcc for windows) and also with visual studio. Up to date details can be found here: http://pygame.org/wiki/CompileWindows


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.

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".


Mac OS X Compiling Info

Up to date instructions for compiling on Mac OS X can be found here: http://pygame.org/wiki/MacCompile



python-gaming.com