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