xref: /aosp_15_r20/external/google-benchmark/docs/python_bindings.md (revision dbb99499c3810fa1611fa2242a2fc446be01a57c)
1# Building and installing Python bindings
2
3Python bindings are available as wheels on [PyPI](https://pypi.org/project/google-benchmark/) for importing and
4using Google Benchmark directly in Python.
5Currently, pre-built wheels exist for macOS (both ARM64 and Intel x86), Linux x86-64 and 64-bit Windows.
6Supported Python versions are Python 3.8 - 3.12.
7
8To install Google Benchmark's Python bindings, run:
9
10```bash
11python -m pip install --upgrade pip  # for manylinux2014 support
12python -m pip install google-benchmark
13```
14
15In order to keep your system Python interpreter clean, it is advisable to run these commands in a virtual
16environment. See the [official Python documentation](https://docs.python.org/3/library/venv.html)
17on how to create virtual environments.
18
19To build a wheel directly from source, you can follow these steps:
20```bash
21git clone https://github.com/google/benchmark.git
22cd benchmark
23# create a virtual environment and activate it
24python3 -m venv venv --system-site-packages
25source venv/bin/activate  # .\venv\Scripts\Activate.ps1 on Windows
26
27# upgrade Python's system-wide packages
28python -m pip install --upgrade pip build
29# builds the wheel and stores it in the directory "dist".
30python -m build
31```
32
33NB: Building wheels from source requires Bazel. For platform-specific instructions on how to install Bazel,
34refer to the [Bazel installation docs](https://bazel.build/install).
35