You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu20.04下Python3.8用pip3安装pygame失败求助

Fixing Pygame Installation Failure on Ubuntu 20.04

Hey there! I see you're hitting a roadblock when trying to install pygame via pip3 install pygame on Ubuntu 20.04—let's get this sorted out quickly.

What's causing the error?

The error logs show missing tools like sdl-config and unfindable freetype2 packages. This happens because pygame needs several system-level development libraries to compile from source (which is what pip tries to do when no pre-built wheel is available for your setup). Without these libraries, the compilation process fails.

Step-by-step solution

  1. Update your system package list first
    Run this command to ensure your package indexes are up to date:

    sudo apt update
    
  2. Install all required dependencies
    Install the full set of development libraries pygame relies on with this single command:

    sudo apt install libsdl1.2-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libfreetype6-dev libportmidi-dev libsmpeg0-dev python3-dev python3-numpy
    

    This covers every missing component mentioned in your error log, including SDL and freetype-related tools.

  3. Reinstall pygame via pip3
    Now that the dependencies are in place, run the installation command again:

    pip3 install pygame
    

Alternative: Install from Ubuntu's repository

If you don't need the absolute latest version of pygame, you can skip the compilation step entirely by installing the pre-built package directly from Ubuntu's repositories:

sudo apt install python3-pygame

内容的提问来源于stack exchange,提问作者Heisenberg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 17:37:55