Skip to content

Instantly share code, notes, and snippets.

@brccabral
Created August 19, 2026 22:56
Show Gist options
  • Select an option

  • Save brccabral/31e043b1740d04529e65823addff51be to your computer and use it in GitHub Desktop.

Select an option

Save brccabral/31e043b1740d04529e65823addff51be to your computer and use it in GitHub Desktop.
Pygame-CE compile from source and build wheel

Pygame-CE compile from source and build wheel

Build wheel with custom libraries

export LD_LIBRARY_PATH=/opt/SDL2/lib
git clone https://github.com/pygame-community/pygame-ce.git
cd pygame-ce
python -m venv .venv
source .venv/bin/activate
python dev.py build --wheel

Use auditwheel to add RPATH and copy the libraries into the wheel.

export LD_LIBRARY_PATH=/opt/SDL2/lib
sudo apt install patchelf
pip install auditwheel
auditwheel repair -w repaired dist/pygame_ce-3.0.0.dev1-cp312-cp312-linux_x86_64.whl

Finally install the repaired wheel.

pip install repaired/pygame_ce-3.0.0.dev1-cp312-cp312-manylinux_2_38_x86_64.whl --force-reinstall

This wheel is ready to share in other systems.

Build same Pygame-CE image

To use the same build as pygame-ce, need to build the image and install the generated wheel.
First, create the docker image with the same dependencies. It takes some time to pull image and compile all dependencies.

cd pygame-ce
cd buildconfig/manylinux-build
make base-image-manylinux2010-x64

Then, use cibuildwheel to build pygame-ce. It will create a docker container, build pygame-ce and export a .whl file back.
cibuildwheel will build many .whl for different Python versions. Edit pyproject.toml to build for a specific version.

[tool.cibuildwheel.linux]
build = "cp312-*"

Then run cibuildwheel

cd pygame-ce
python -m venv .venv
source .venv/bin/activate
python -m pip install cibuildwheel auditwheel
CIBW_MANYLINUX_X86_64_IMAGE=pygame/manylinux2010_base_x86_64:latest CIBW_DEBUG_KEEP_CONTAINER=TRUE python -m cibuildwheel --platform linux

The .whl file will contain all dependencies. Just install it

cd pygame-ce
source .venv/bin/activate
pip install wheelhouse/pygame_ce-3.0.0.dev1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl --force-reinstall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment