简体   繁体   English

Ubuntu Python 3 上的 Pygame

[英]Pygame on Ubuntu Python 3

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我有 Ubuntu,我想在 Python 3 上使用 pygame。我安装了pygame

sudo apt-get python-pygame

but it just doesn't work when I type但是当我输入时它不起作用

import pygame    

Please help!请帮忙!

You must install pip for python3你必须为python3安装pip

$ sudo apt install python3-pip

and then, with the pip installed, install pygame然后,安装 pip 后,安装 pygame

$ pip3 install pygame

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 Ubuntu 上的pygame 包只支持python 2.7,所以如果你使用python 3 是不可能导入的。如果你想要python 3.x 支持,你需要安装位于https://bitbucket 的pygame 1.9.2 。组织/pygame/pygame/下载

If you have all the dependencies installed, it should be as simple as running setup.py如果您安装了所有依赖项,它应该像运行 setup.py 一样简单

Ubuntu 19.04 and later Ubuntu 19.04 及更高版本

To install python3-pygame in Ubuntu 19.04 and later open the terminal and type:要在 Ubuntu 19.04 及更高版本中安装 python3-pygame,请打开终端并键入:

sudo apt install python3-pygame

Ubuntu 18.10 Ubuntu 18.10

To install python3-pygame in Ubuntu 18.10 open the terminal and type:要在 Ubuntu 18.10 中安装 python3-pygame,请打开终端并输入:

sudo nano /etc/apt/sources.list  

Add this line to sources.list.将此行添加到 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使用键盘组合Ctrl + O保存 sources.list 并按Enter并使用Ctrl + X退出

Update the list of available software and install python3-pygame.更新可用软件列表并安装 python3-pygame。

sudo apt update  
sudo apt install python3-pygame  

Ubuntu 16.04-18.04 Ubuntu 16.04-18.04

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

I'm at a Pop-OS 20.04 machine and all of those answers didn't work for me (◉_◉).我在 Pop-OS 20.04 机器上,所有这些答案对我都不起作用(◉_◉)。 So I went to the documentation of Pygame and realized that I had to have the dependencies installed.所以我查看了 Pygame 的文档并意识到我必须安装依赖项。 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:现在您已准备好安装 Pygame,因此git clone其 GitHub 存储git clone到您当前的文件夹中,然后pip install模块:

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=如果您使用的是 Python 2,请访问此 URL: https : //www.pygame.org/wiki/CompileUbuntu?parent=

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM