12

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?

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

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
    
  • I'm at Ubuntu 14.04 with python 3.4, works for me. Thanks – ifyalciner Feb 23 '16 at 14:09
  • 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! – Gabriel Staples Sep 14 '16 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. – Gabriel Staples Sep 14 '16 at 21:13
  • I also had to run sudo apt-get install python3-setuptools – Moebius Oct 4 '16 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
2

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
    
  • Worked for me for Ubuntu 18.04 – Kingsley Nov 19 '18 at 0:08
1

Ubuntu 18.10 and later

To install python3-pygame in Ubuntu 18.10 and later 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 # for 19.04 replace cosmic with disco 

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 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.