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?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityThe 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.
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
I can confirm Jobin's suggestion in his comment:
sudo apt-get install python-pygame
Works flawlessly. Tested on 13.10.
Next time if you want to install a python package you can search whether it is in the repositories by running:
apt-cache search pygame
Then you can see the packages (if they are in the repositories) and their names. The output for apt-cache search pygame
is
lightyears - single player real-time strategy game with steampunk sci-fi
psychopy - environment for creating psychology stimuli in Python
pyntor - flexible and componentized presentation program
python-pygame - SDL bindings for games development in Python
python-pyglet - cross-platform windowing and multimedia library
python-soya - high level 3D engine for Python
python-soya-dbg - high level 3D engine for Python - debug extension
python-soya-doc - high level 3D engine for Python
solarwolf - Collect the boxes and don't become mad
In this list you can select the package (here: python-pygame
) and run sudo apt-get install the-package-name
.
For more debugging of dependencies see Installing pygame with pip.
'import pygame'
or import pygame
(without the '')?
To install PyGame for Python 3.x on Ubuntu 19.04 and later open the terminal and type:
sudo apt install python3-pygame
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 # 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
To install python-pygame in 20.04 and earlier open the terminal and type:
sudo apt install python-pygame
If you have done all the steps above and still are getting the ModuleNotFoundError then you might be using some version of Python that does not support/or was not installed Pygame into.
Try typing, python2.7
or python3.6
or a terminal.
If you are using the Thonny IDE go under:
sudo apt-get install python-pygame
?