Ubuntu20.04下Python3.8用pip3安装pygame失败求助
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
Update your system package list first
Run this command to ensure your package indexes are up to date:sudo apt updateInstall 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-numpyThis covers every missing component mentioned in your error log, including SDL and freetype-related tools.
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

