One, use pip to install Python package
Most newer versions of Python come with a pip, so first check to see if the system already has PIP installed. In Python3, Pip is sometimes referred to as PIP3.
1. Check if PIP is installed in Linux and OS X systems
Open a terminal window and execute the following command:
In Python2.7:
[Email protected]:~$ pip--version
Pip 8.1.1 from/usr/lib/python2.7/dist-packages (Python 2.7)
In python3.x:
[Email protected]:~$ pip3--version
Pip 8.1.1 from/usr/lib/python3/dist-packages (Python 3.5)
If it does not exist, you need to install PIP
The commands for installing PIP in the terminal are:
sudo apt install python-pip
The commands to install PIP3 in the terminal window are:
sudo apt install python3-pip
Second, install Pygame in Linux system
If we are using Python2.7, please use Package Manager to install Pygame. To do this, open a terminal window and execute the following command, which will download the Pygame and install it into our system:
$ sudo apt-get install Python-pygame
If we are using Python3, we need to perform two steps: install Pygame dependent libraries , download and install Pygame.
Execute the following command to install the Pygame dependent library (if we are using command Python3.5 to start a terminal session, replace Python3-dev with Python3.5-dev):
$ sudo apt-get install Python3-dev mercurial
$ sudo apt-get install Libsdl-image1.2-dev libsdl2-dev Libsdl-ttf2.0-dev
If we need to enable some of the advanced features of Pygame, such as the ability to add sounds, you can install these additional libraries:
$ sudo apt-get install Libsdl-mixer1.2-dev Libportmidi-dev
$ sudo apt-get install Libswscale-dev libsmpeg-dev libavformat-dev Libavcodec-dev
$ sudo apt-get install Python-numpy
Next, execute the following command to install Pygame (replace PIP with PIP3 if necessary):
HG Clone Https://bitbucket.org/pygame/pygame
CD Pygame
Python3 setup.py Build
sudo python3 setup.py instal
Or try $pip install--user hg+http://bitbucket.org/pygame/pygame if it works
To confirm that the installation was successful, start a Python terminal session and try to import Pygame by executing the following command:
$ python3
>>> Import Pygame
>>>
Python Module Pygame Installation