Using Pygame with PyPy

pygame isn't compatible with pypy, so to use it you'll have to stick with cPython.


Update (April 2018):

As pointed out by in this answer the PyPy v6.0 release now works with pygame - although not yet with the current stable (pygame 1.9.3) release, but with the current developement branch (1.9.4.dev0).

tested on ubuntu 17.10 by:

  • downloading and extracting the latest precompiled version for linux
  • installing the build dependencies for pygame: sudo apt build-dep python-pygame
  • installing pip: ./bin/pypy3 -m ensurepip
  • installing pygame: ./bin/pypy3 -m pip install 'Pygame>=1.9.4.dev0'
  • running the demo: ./bin/pypy3 -m pygame.examples.aliens

Works for both the pypy3 and pypy2 versions.


Pygame games actually spend very little of their time running python code. The vast, vast majority is spent doing SDL fill and flip operations. Most fills are unnecessary. How important is this? Well, take my computer. Say you write a game that has a loop that just paints the background one color. It will get about 40 fps. This is because it's basically going to every pixel individually and writing to it. This is using 200 x 300 = 60000 operations every frame to do nothing.

So instead of painting the entire background, just paint the parts that were drawn on the previous frame.

This makes your code a bit more complicated, but it produces a huge performance increase.

Also, don't forget to run cProfile to see where the problem areas are. Look, don't guess.


It looks like PyPy v6 (April 2018) will improve the situation and make PyPy compatible with PyGame and other C python extensions. See https://renesd.blogspot.co.uk/2018/03/pygame-on-pypy-usable.html for an example.