14

I am using Ubuntu 13.10.I have both python 2.7 and python 3.3.I have installed pygame properly in python 2.7.How can i install it in python3.3.Does pygame support python3.3 or not?

3
  • 2
    sudo apt-get install python-pip; sudo pip install pygame ?
    – Gustaf
    Jan 8, 2014 at 14:24
  • 2
    @Gustafpython3-pip and pip3 should be used
    – warvariuc
    Jan 18, 2014 at 10:56
  • 1
    Starting in 18.10 Pygame for Python 3 (python3-pygame) is an apt package.
    – karel
    Nov 1, 2018 at 16:02

4 Answers 4

17

Here's a link to a solution for Ubuntu 12.04. Hope it helps. From the terminal:

  1. Change to your home directory.

    cd ~
    
  2. Get Pygame source code.

    sudo apt-get install mercurial
    hg clone https://bitbucket.org/pygame/pygame
    cd pygame
    
  3. Install dependencies.

    sudo apt-get install python3-dev python3-numpy libsdl-dev libsdl-image1.2-dev \
      libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev libportmidi-dev \
      libavformat-dev libswscale-dev libjpeg-dev libfreetype6-dev
    
  4. Build and install Pygame.

    python3 setup.py build
    sudo python3 setup.py install
    
4
  • I'm at Ubuntu 14.04 with python 3.4, works for me. Thanks
    – ifyalciner
    Feb 23, 2016 at 14:09
  • 1
    I'm running Xubuntu 16.04 LTS with Python 3.5.2. Before it would let me build it, per your instructions above, I also had to install setuptools via sudo apt-get install python3-setuptools (source: stackoverflow.com/a/14426553/4561887). Everything else worked great! Sep 14, 2016 at 19:10
  • I attempted to add this dependency into your answer via an edit, but it was rejected, so I just posted another answer instead, per the edit reviewers' recommendations. Sep 14, 2016 at 21:13
  • I also had to run sudo apt-get install python3-setuptools
    – Moebius
    Oct 4, 2016 at 17:14
4

Unfortunately you need to recompile it. And unfortunately the last stable version (1.9.1) doesn't support python 3...

So you need to download the last source code from the trunk, hopping it's not broken at this moment:

sudo apt-get install mercurial
hg clone https://bitbucket.org/pygame/pygame

You also need to download the build dependency:

sudo apt-get build-dep pygame
sudo apt-get install python3-dev
sudo apt-get install python3-numpy

This will install dependency used by the version of pygame available on your package depot. Newer version maybe need other dependency! We also need to specify python3-dev and python3-numpy because, well, build-dep will install python2 version of this packages...

You can now run:

cd pygame
python3 config.py

If some dependency are missing config.py will list them and ask if you want to continue if this dependency are not mandatory. You can install them if you want/can or simply ignore it and probably loss some functionality.

Now it's time to build and install:

python3 setup.py build
sudo python3 setup.py install
3

I attempted to add this to the accepted answer, but it was rejected, so I'm posting it as a separate answer.

In more recent versions of Ubuntu and Ubuntu derivatives (ex: Xubuntu 16.04 LTS), the accepted answer is missing one important dependency before calling the build command, namely: python3-setuptools. Therefore, I'm posting this answer with that dependency added.

I've successfully completed the steps below in Xubuntu 16.04 LTS in order to install pygame into Python 3.5.2.

(Note: to install pygame into Python 2 simply use sudo apt-get install python-pygame).

To install it into Python 3.x, do the following:

(Original source: http://heritagerobotics.wordpress.com/2012/11/20/compiling-pygame-for-python-3-2-in-xubuntu/)

  1. Change to your home directory.

    cd ~
    
  2. Get Pygame source code.

    sudo apt-get install mercurial
    hg clone https://bitbucket.org/pygame/pygame
    cd pygame
    
  3. Install dependencies.

    sudo apt-get install python3-dev python3-numpy libsdl-dev libsdl-image1.2-dev \
      libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev libportmidi-dev \
      libavformat-dev libswscale-dev libjpeg-dev libfreetype6-dev python3-setuptools
    
  4. Build and install Pygame.

    python3 setup.py build         #build by passing the "build" command as an argument to the setup.py module
    sudo python3 setup.py install  #install by passing the "install" command as an argument to the setup.py module
    
1
  • 1
    Worked for me for Ubuntu 18.04
    – Kingsley
    Nov 19, 2018 at 0:08
2

Ubuntu 19.04 and later

To install PyGame for Python 3.x on Ubuntu 19.04 and later open the terminal and type:

sudo apt install python3-pygame

Ubuntu 18.10

To install PyGame for Python 3.x on Ubuntu 18.10 open the terminal and type:

sudo nano /etc/apt/sources.list  

Add this line to sources.list.

deb http://archive.ubuntu.com/ubuntu/ cosmic-proposed universe 

Save sources.list with the keyboard combination Ctrl+O and press Enter and exit with Ctrl+X

Update the list of available software and install python3-pygame.

sudo apt update  
sudo apt install python3-pygame 

Ubuntu 14.04-18.04

sudo apt install python3-pip
python3 -m pip install pygame
2
  • Any solution for 18.04?
    – MestreLion
    Nov 3, 2019 at 18:38
  • Besides the obvious pip install solution in 18.04, the other alternative is to manually download the python3-pygame .deb file for 19.04 and install it in 18.04. All the required dependencies are available in the 18.04 default repositories.
    – karel
    Nov 3, 2019 at 18:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .