Skip to main content

CompileWindows — wiki

Compile pygame on windows

There are three steps.

  • Get a C/C++ compiler.
  • Checkout pygame from github.
  • Run the pygame install commands.

Step 1, Get a C/C++ compiler.

These are the compilers you'll need.

These will download the required dependencies and build for SDL2(experimental) or SDL1.

Step 2, Checkout pygame from github.

To get pygame from github, you might need to install git. This is a good command line option for git checkouts on windows. https://gitforwindows.org/

Here is the pygame github repo where the code lives. https://github.com/pygame/pygame

Step 3, Run the pygame install commands.

SDL1 instructions.

git clone https://github.com/pygame/pygame.git
cd pygame
pip install setuptools requests -U
python -m buildconfig
python setup.py install
python -m pygame.examples.aliens

SDL2 instructions.

git clone https://github.com/pygame/pygame.git
cd pygame
python -m pip install setuptools requests -U
python -m buildconfig -sdl2 --download
python setup.py install
python -m pygame.examples.aliens

More information

Compiler information pages for windows.

old instructions

There are here for historical interest.

The incomplete guide with mingw is here: Compiling with MingW gcc on windows.

The incomplete guide with the Visual Studio 2003 Toolkit compiler is here: Compiling with the Toolkit Compiler.

Potential Issues

Attempt to compile pygame on Windows - 21/04/2020 - Python 3.8.2, 32 bit

Following these steps:

  1. Download Visual Studio Build Tools 2017 & Windows 10 SDK from here
  2. Then try the following steps:
    git clone https://github.com/pygame/pygame.git
    cd pygame
    python -m pip install setuptools requests -U
    python -m buildconfig -sdl2 --download
    python setup.py install
    python -m pygame.examples.aliens
    
  3. For me, this produced a
    distutils.errors.DistutilsPlatformError: Unable to find vcvarsall.bat
    
    error on step:
    python -m buildconfig -sdl2 --download
    
  4. From there I edited part of 'buildconfig/config_win.py' on line #454 to read:
    find_lib=r'freetype[-0-9]*\.lib'
    
    And line #463 to read
    find_lib=r'(lib)?png[-0-9]*\.lib'
    
    And line #468 to read
    find_lib=r'(lib)?jpeg\.lib'
    
    Which let the process compile past that step.
  5. After that I got one error on
    python setup.py install
    
    Reading:
    prebuilt-x86/include\ft2build.h(56): fatal error C1083: Cannot open include file: 'freetype/config/ftheader.h': No such file or directory
    
    To fix this I moved the 'freetype' folder from 'pygame\prebuilt-x86\include\freetype2' to 'pygame\prebuilt-x86\include\' and it then seemed to compile all the way to the end.
  6. At the end I could run some pygame projects so long as they didn't use the imageext module which seemed not to work.