4

I have searched everywhere. There is no answer for my specific problem! I have Ubuntu, I want to use pygame on Python 3. I installed the pygame package with

sudo apt-get python-pygame

but it just doesn't work when I type

import pygame    

Please help!

0

4 Answers 4

6

You must install pip for python3

$ sudo apt install python3-pip

and then, with the pip installed, install pygame

$ pip3 install pygame
Sign up to request clarification or add additional context in comments.

Comments

3

Ubuntu 19.04 and later

To install python3-pygame in Ubuntu 19.04 and later open the terminal and type:

sudo apt install python3-pygame

Ubuntu 18.10

To install python3-pygame in 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 16.04-18.04

sudo apt install python3-setuptools
sudo easy_install3 pip
python3 -m pip install --user pygame

Comments

2

The pygame package on Ubuntu is only for python 2.7, so it is impossible to import if you use python 3. If you want python 3.x support, you need to install pygame 1.9.2 which is located at https://bitbucket.org/pygame/pygame/downloads

If you have all the dependencies installed, it should be as simple as running setup.py

Comments

0

I'm at a Pop-OS 20.04 machine and all of those answers didn't work for me (◉_◉). So I went to the documentation of Pygame and realized that I had to have the dependencies installed. To do that you can:

sudo apt-get install git python3-dev python3-setuptools python3-numpy python3-opengl \
    libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev \
    libsdl1.2-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev \
    libtiff5-dev libx11-6 libx11-dev fluid-soundfont-gm timgm6mb-soundfont \
    xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic fontconfig fonts-freefont-ttf libfreetype6-dev

Now you are ready to install Pygame, so git clone their GitHub repository into your current folder and pip install the module:

git clone https://github.com/pygame/pygame.git

If you are using Python 2 go to this URL: https://www.pygame.org/wiki/CompileUbuntu?parent=

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.