问题
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!
回答1:
You must install pip for python3
$ sudo apt install python3-pip
and then, with the pip installed, install pygame
$ pip3 install pygame
回答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
回答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 18.04
Besides the obvious pip install solution in 18.04, the other alternative is to manually download the python3-pygame .deb file for 19.04 and install it with sudo apt ./python3-pygame_1.9.4.post1+dfsg-3_amd64.deb in 18.04. All the required dependencies are available in the 18.04 default repositories.
来源:https://stackoverflow.com/questions/26855293/pygame-on-ubuntu-python-3