How to install Pygame for use with Python 3.x on Ubuntu 12.04?

Today, I had some trouble installing pygame for use with python 3.2. Pygame for python 2.7 is easy: you can get that through apt-get. For use with python 3.x you need to build pygame from source. I followed the instructions from the pygames website:

All seemed to work just fine, until I tried to use the new module:

>>> import pygame

This raised the following error message:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import pygame
  File "/usr/local/lib/python3.2/dist-packages/pygame/", line 95, in <module>
    from pygame.base import *
ImportError: /usr/local/lib/python3.2/dist-packages/pygame/ undefined symbol: PyCObject_Check

It took me some time to find a solution, but I finally got everything working just fine. Because many others seem to be struggling with the same issue - and some even say it's not possible! - I thought it might be useful to share my solution.

First, install the following dependencies:

sudo apt-get install python3-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python3-numpy subversion libportmidi-dev ffmpeg libswscale-dev libavformat-dev libavcodec-dev

Next, download the latest edition of pygame from the subversion repository:

svn co svn:// pygame

And finally, build and install it:

cd pygame
python3 build
sudo python3 install 

Good luck!


PS All the information is on the pygame website. You just have to make the right combinations : )
Shared publiclyView activity