<br />

This page describes how to build the MediaPipe Python wheel package from source
using Docker. You can use the built wheel package to install MediaPipe on a
local [Linux x86_64 machine](https://developers.google.com/edge/mediapipe/solutions/build_python#manylinux) or [Raspberry Pi (ARM64)](https://developers.google.com/edge/mediapipe/solutions/build_python#raspberry-pi).

## Prerequisites

To build the Python wheel package, your system requires the following:

- Docker with BuildKit support (Docker 18.09 or higher)

The Python build pipeline supports Python 3.9 or later (3.9--3.14).

## Invoke build using Docker

You can use one of the Dockerfiles in the [MediaPipe
repository](https://github.com/google-ai-edge/mediapipe):

- [`Dockerfile.manylinux_2_28_x86_64`](https://github.com/google-ai-edge/mediapipe/blob/master/Dockerfile.manylinux_2_28_x86_64) builds `manylinux_2_28` wheels compatible with x86_64 Linux hosts.
- [`Dockerfile.manylinux2014_aarch64rp4`](https://github.com/google-ai-edge/mediapipe/blob/master/Dockerfile.manylinux2014_aarch64rp4) builds Raspberry Pi wheels with `aarch64` support.
- [`Dockerfile`](https://github.com/google-ai-edge/mediapipe/blob/master/Dockerfile) sets up the C++ MediaPipe framework build environment.

## Manylinux image for x86_64

Clone the [MediaPipe repository](https://github.com/google-ai-edge/mediapipe/)
and run the following commands from the repository root to build an x86_64
`manylinux_2_28` wheel. By default, `Dockerfile.manylinux_2_28_x86_64` builds
for Python 3.12 (`cp312-cp312`); if targeting another Python version, update
both `PYTHON_BIN` and the `auditwheel repair` path in the Dockerfile to match.

Build the Docker image:

    DOCKER_BUILDKIT=1 docker build \
      -f Dockerfile.manylinux_2_28_x86_64 \
      -t mp_manylinux . \
      --build-arg "PYTHON_BIN=/opt/python/cp312-cp312/bin/python3.12"

Create a temporary container from the built image:

    docker create -ti --name mp_pip_package_container mp_manylinux:latest

Copy the repaired `manylinux` wheel from `/wheelhouse` to your local machine:

    docker cp mp_pip_package_container:/wheelhouse/. wheelhouse/

Remove the temporary Docker container:

    docker rm -f mp_pip_package_container

## Raspberry Pi image on ARM

Clone the [MediaPipe repository](https://github.com/google-ai-edge/mediapipe/)
and run the following commands from the repository root to build an `aarch64`
wheel for 64-bit Raspberry Pi OS. By default,
`Dockerfile.manylinux2014_aarch64rp4` builds for Python 3.12
(`/opt/python/cp312-cp312/bin/python3.12`), and accepts `--build-arg
PYTHON_BIN=...` for other pre-installed `/opt/python/` versions
(`cp39`--`cp314`).

Build the Docker image:

    DOCKER_BUILDKIT=1 docker build \
      -f Dockerfile.manylinux2014_aarch64rp4 \
      -t mp_manylinux_aarch64rp4 .

Create a temporary container from the built image:

    docker create -ti --name mp_pip_package_container mp_manylinux_aarch64rp4:latest

Copy the repaired `manylinux` wheel from `/wheelhouse` to your local machine:

    docker cp mp_pip_package_container:/wheelhouse/. wheelhouse/

Remove the temporary Docker container:

    docker rm -f mp_pip_package_container