Compile pygame on windows¶
Download Pygame for free. Set of Python modules designed for writing video games. Pygame is a Free and Open Source python programming language library for making multimedia applications like games built on top of the excellent SDL library. Like SDL, pygame is highly portable and runs on nearly every platform and operating system. On Sun, Sep 27, 2015 at 11:38 AM, Lenard Lindstrom wrote: Pygame installers for 64-bit Python 2.7 and 3.4 are now available at the Bitbucket download page.
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.
- Python 2.7: Microsoft Visual C++ Compiler for Python 2.7 ( download link )
Python 3.6+ Install Microsoft Build Tools for Visual Studio 2017.
The setuptools Python package version must be at least 34.4.0.
- Make sure this checkbox is ticked: '[ ] MSVC v140 - VS 2015 C++ build tools (v14.00)'
Pygame Download Windows 10 64 Bit
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.¶
SDL2 instructions.¶
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.
Compilation Logs/Attempts ¶
These may be useful for people encountering issues attempting to compile on windows as depending on what version of python and Visual Studio you use, things can get more interesting. The most successful attempt so far with python 3.8 is at the bottom.
Attempt to compile pygame on Windows - 21/04/2020 - Python 3.8.2, 32 bit¶
Following these steps:
- Download Visual Studio Build Tools 2017 & Windows 10 SDK from here
- Then try the following steps:
- For me, this produced a error on step:
- From there I edited part of 'buildconfig/config_win.py' on line #454 to read: And line #463 to read And line #468 to read Which let the process compile past that step.
- After that I got one error on Reading: To fix this I moved the 'freetype' folder from 'pygameprebuilt-x86includefreetype2' to 'pygameprebuilt-x86include' and it then seemed to compile all the way to the end.
- At the end I could run some pygame projects so long as they didn't use the imageext module which seemed not to work.
Attempt to compile pygame on Windows - 02/09/2020 - Python 3.8.5, 32 bit¶
This attempt was successful (imageext module fully working) but I encountered a few issues along the way.
Visual Studio build tools installed (don't know if all of these are crucial but they were the defaults for me):
- MSVC v142 - VS2019 C++ x64/x86 build tools (v 14.27)
- Windows 10 SDK (10.0.18362.0)
- C++ CMake tools for windows
- Testing tools core features - Build Tools
- C++ AddressSanitizer (Experimental)
Once those were downloaded and installed I loaded up the 'Developer Command Prompt for VS 2019' to try a compile. Make sure that you pick correct prompt 32 or 64 bit prompt. Following the instructions above, but using one additional step at the start:
2020-10-07 / jtiai
Documentation of setuptools/distutils do say that both DISTUTILS_USE_SDK and MSSdk environment variables must be defined. After that config and building should work without issues. I didn't need to do steps below to modify any files.
Pygame Download 64-bit
At first this didn't work for me, failing with an error because disutils was failing to find the install location of the Visual Studio Build Tools. I'm not sure if there is a better way to correct this but I was able to make two small changes to msvc.py which is located at:
The first change was adding the literal path to the build tools into the code on line 862. The block of code now looks like this:
The second change was to change the index into a sub-directory where it was clearly looking into the wrong one, this is around line 1709 and now looks like this:
with the original -1 (picking the last sub-directory in the list) changed to a 0 (picking the first).
With those two changes I was able to run (note from jtiai 2020-10-07: using below both 32 and 64 bit compilation works and no changes in files were required:
And this time it all compiled successfully. I also tried the same process but with x64 bit python - but it failed and despite some tweaking, I wasn't able to resolve it and get 64 bit pygame compiled on windows.
Update - Report from jtai on Discord that setting: Is required to make the 64bit build work.