Skip to main content

Porting Pygame 1.9 to Python 3 — wiki

Edit: Note, pygame works on python3 for some years now.

the goal

The goal is to make Pygame compatible with both Python 2.x and Python 3. So far most Python 1.9.2a0 modules build and pass their unit tests in Python 3. The corresponding examples also run. A major milestone was the release of NumPy for Python 3.1 in August, 2010. Pygame surfarray and sndarray are now ported. Some issues regarding Unicode file paths are being dealt with in the fsencoding branch. This will soon be merged back into trunk.

progress report

April 14, 2009:

python3 branch:

The build chain, config.py and setup.py, have been modified for Unix and Windows.These can run from Python 3.0 and successfully build updated modules.

At this point the following modules have been updated: base, surface, surflock, rect, color, constant. The pygame package __init__ has also been updated. The unit test framework has been reworked enough to allow the individual unit test modules to run as stand-alone programs. The rect and color modules fully pass their unit tests.

trunk

The changes to the python3 __init__.py have been merged back into the trunk. The compat.py module was also added.

April 22

The minimal requirements of getting the chimp.py and aliens.py examples running were met. The following modules were updated:

  • color (color.c)
  • display (display.c)
  • event (event.c)
  • font (font.c)
  • gfxdraw (gfxdraw.c)
  • image (image.c, imageext.c)
  • key (key.c)
  • local (local.py)
  • mixer (mixer.c)
  • mixer.music (music.c)
  • mouse (mouse.c)
  • pygame (__init__.py)
  • rect (rect.c)
  • rwobject (rwobject.c)
  • sprite (sprite.py)
  • surface (surface.c)
  • surflock (surflock.c)
  • transform (transform.c)

The following unit tests were also update:

  • base_test.py
  • blit_test.py
  • color_test.py
  • event_test.py
  • font_test.py (trivial)
  • image_test.py
  • mixer_test.py
  • mouse_test.py (trivial)
  • rect_test.py
  • sprite_test.py
  • surface_test.py
  • time_test.py (trivial)
  • transform_test.py

The following examples have been updated:

  • aacircle.py
  • aliens.py
  • chimp.py
  • fonty.py
  • scaletest.py
  • stars.py

September 1, 2010

Further modules ported to Python 3.1. Though all ported modules now pass their unit tests further testing is needed.

  • draw
  • midi
  • movie
  • math
  • surfarray
  • sndarray
  • freetype

All examples except camera, overlay, vgrade, __movie and scrap_clipboard are considered ported.

todo

  • Complete unicode file name handling (fsencoding branch), then merge back into trunk (by mid Sept/10).
  • update documentation to explain Unicode in Pygame
  • work out final solution for open Python 3 IOBase objects: how to check abstract types from C. (Sept. 1, 2010) Probably the most practical solution is to just do duck typing.
  • _movie - deferred until module is ready for release
  • scrap (does some C string stuff that makes porting difficult)
  • camera - what is the status of this module?

References