Pygame python3.x Installation

A place where you can post Python-related tutorials you made yourself, or links to tutorials made by others.

Pygame python3.x Installation

Postby metulburr » Thu Apr 25, 2013 2:58 am

When first starting with pygame, i had a headache of a time figuring out how to install pygame for linux on python3.x. And anytime i reinstall one of my distro's i still have to find this to install pygame on that distro. So this was my cheat sheet for all my computers that i had to install pygame on. Feel free to add, modify anything that is needed. Especially Windows installation, because i am moslty on linux, i do not bother installing it under Windows. This cheat cheet without took me hours to figure out googling around trying to find info about. Since having it, pygame is a quick 1 minute install on a fresh distro.


mac: ... os_x_1094/ ... ricks_and/

Code: Select all
sudo apt-get install python-pygame
(or whatever package manager), and assuming python is referring to python2.x, otherwise the package name would be python2-pygame

Code: Select all
ImportError: /usr/local/lib/python3.2/dist-packages/pygame/ undefined symbol: PyCObject_Check

This error means you are running pygame 1.9.1 under python3.x. Which has some problems. Actually i have no idea what this error means, but it means have fun with getting pygame to work with python3.x. There are some methods to getting this to work, but i found pygame 1.9.2 pre works without modification. I found the modification to 1.9.1 would work in Ubuntu, but not in Arch, whereas pygame 1.9.2 pre worked in every distro i tried.

1) Download the latest pygame 1.9.2 pre and extract it ... rce/pygame

Code: Select all
sudo apt-get install mercurial
hg clone

2) if you already installed 1.9.1, and installed it under python3.x, then remove it:
in directory: ( replace python3.2, with whichever version you have
Code: Select all

execute these two commands:
Code: Select all
sudo rm -r pygame
sudo rm pygame-1.9.1release.egg-info

3) install python3 pygame dependencies:
Code: Select all
sudo apt-get install python3-dev python-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python3-numpy python-numpy subversion libportmidi-dev libfreetype6-dev

(which some are not python3 pygame dependant, but whatever)
for example if you do not download you will get this error:
Code: Select all
src/pygame.h:75:20: fatal error: Python.h: No such file or directory compilation terminated. error: command 'i686-linux-gnu-gcc' failed with exit status 1

4) change directory to the newly donwloaded/extracted pygame directory and execute:
Code: Select all
sudo python3 install

Code: Select all
Hunting dependencies...
SDL     : found 1.2.14
FONT    : found
IMAGE   : found
MIXER   : found
SMPEG   : found 0.4.5
PNG     : found
JPEG    : found
SCRAP   : found
AVFORMAT: not found
SWSCALE : not found
FREETYPE: found 2.4.8

Warning, some of the pygame dependencies were not found. Pygame can still
compile and install, but games that depend on those missing dependencies
will not run. Would you like to continue the configuration? [Y/n]:

will display that some games may not work, etc. yatta yatta, hit y for yes. Although make sure SDL is found, MPEG, IMAGE, FONT. i have not yet came across a game that i couldnt run, yet, with these two that were not found.

6) confirm installation:
Code: Select all
metulburr@ubuntu:~$ python3
Python 3.2.3 (default, Oct 19 2012, 20:10:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame

if you get the prompt, you are good to go.

EDIT: well i get sick of redoing this with every ubuntu distro, so this now replaces theis whole thing as it does more than just pygame

I tried the latest python 3.3 with Pygame 1.9.2 and it failed, however python3.2 worked with it. So you may have to tinker around with the versions possibly.

I did end up getting python3.4 working with a pygame version for arch linux. PAckage is:

Code: Select all
makepkg -s
sudo pacman -U *.xz

Code: Select all
metulburr@rch ~/Downloads/python-pygame-hg $ python
Python 3.4.0 (default, Mar 17 2014, 23:20:09)
[GCC 4.8.2 20140206 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
>>> exit()
metulburr@rch ~/Downloads/python-pygame-hg $
Last edited by metulburr on Mon Dec 15, 2014 10:16 pm, edited 18 times in total.
Reason: added dependency pckage for freetype
we will be moving to on October 1 2016
more details here
User avatar
Posts: 2228
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest