Does pygame work with Python3?

Martin Bryant
Martin Bryant
500
| 4 1 2
Asked on 2/6/15, 1:39 PM
1
vote
343 Views

In short yes, but no one said that it was easy... Details here... http://www.pygame.org/wiki/FrequentlyAskedQuestions#Does Pygame work with Python 3? We need to use pygame 1.9.2, which is available for Windows, but not Ubuntu as far as I can see. Martin

Martin Bryant
on 2/6/15, 1:41 PM

I've managed to get pygame working with python3 on Ubuntu. The downside is that this involved building from source. If anyone wants to give this a try, the first step is to install 'mercurial' (which is the version control system which Pygame is developed using). This can be done with 'sudo apt-get install mercurial' (or 'sudo aptitude install mercurial' if you prefer to use aptitude). The pygame code can then be 'checked out' (downloaded) to your current directory with 'hg clone https://bitbucket.org/pygame/pygame'. Once complete, you should have a new subdirectory called 'pygame' with the code in.

The next step is to compile and install the code. However, in order to install for python3 rather than python2, I had to make a small change to the Makefile. Open the file in your favourite editor and change line 4 from 'PYTHON = python' to 'PYTHON = python3'. Save and close the file, and (from within the pygame directory) you should hopefully be able to perform the compilation and installation using the 'standard Linux combo' of commands: './configure', 'make', 'sudo make install'. If this finishes successfully, then try running 'python3', and importing pygame:

tom@alexandria $ python3
Python 3.2.3 (default, Feb 27 2014, 21:31:18)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
>>> pygame.__version__
'1.9.2a0'
>>>

 

Huzzah!

Tom Pickering
Tom Pickering
30
| 2 0 0
Answered on 2/7/15, 4:08 PM
1
vote

I think the installation seems pretty sound; I've been able to adapt my pygame-based ninja game to be python3 compatible, and it now runs nicely under both 2 and 3. If anyone else has much trouble with this approach, there are also quite a few alternatives to pygame such as pysdl, pyget and python-sfml (which I recall being rather nice to use; my TetraBall game uses SFML).

Tom Pickering
on 2/7/15, 4:49 PM

Tom, Thanks a ton. I had a lot of trouble trying to install this and this worked like a dream. Now I'll start working on learning git so that we can work together. Martin

Martin Bryant
on 2/10/15, 9:16 PM

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Ask a Question

Keep Informed

About This Forum

This community is for professionals and enthusiasts of our products and services.

Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/6/15, 1:39 PM
Seen: 343 times
Last updated: 2/10/15, 9:16 PM