How to install pygame?

I am running Ubuntu 13.10. I have python 2.7.5 with anaconda 1.8.0. Whenever I start python and type import pygame it tells me that there is no module named pygame.

How can I install pygame?


Solution 1:

The reason you are not able to import pygame into your python interpreter is because you are installing it for python2 and starting the python3 interpreter(Ubuntu 13.10 uses python3 by default).

To install pygame for python2(your version is 2.7.5), do this on a terminal(Ctrl+Alt+t):

sudo apt-get install python-pygame

and then start the python2 interpreter

python2

and then try to import pygame as

import pygame

To set python2 as your default interpreter, you can set an alias in your bash_aliases file. To do this, open a terminal and type:

nano ~/.bash_aliases

This may open an empty file, depending upon whether you have set an alias before and then type

alias python='python2'

Do not change symlinks in /usr/bin/python3, since this may break many application in Ubuntu 13.10 which use python3 vociriferously.

Solution 2:

This should install pygame for python 3, as python3-pip is required for pygame.

 sudo apt-get install python3-pip python3-dev  
 sudo pip3 install pygame