In fact, it is not difficult to install pygame under Ubuntu, but it is very troublesome if it is wrong.
At that time, I first found this installation command: sudo apt-get install python-pygame was executed, the installation was successful, and then run, and found that an error was reported:
Index Error: bytes to write exceed buffer size
This error has few hints, and there are few online answers. Later, I found the same in carla-issue, saying that it was caused by apt installation of pygame. The correct way should be to use pip
So first delete the apt installation: sudo apt-get --purge remove python-pygame
Then re-pip install:
sudo pip install pygame or
sudo pip3 install pygame
This process will be time-consuming