18 KiB
cibuildwheel
Python wheels are great. Building them across Mac, Linux, Windows, on multiple versions of Python, is not.
cibuildwheel is here to help. cibuildwheel runs on your CI server - currently it supports GitHub Actions, Azure Pipelines, Travis CI, AppVeyor, CircleCI, and GitLab CI - and it builds and tests your wheels across all of your platforms.
What does it do?
| macOS Intel | macOS Apple Silicon | Windows 64bit | Windows 32bit | manylinux x86_64 | manylinux i686 | manylinux aarch64 | manylinux ppc64le | manylinux s390x | |
|---|---|---|---|---|---|---|---|---|---|
| CPython 3.6 | ✅ | N/A | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| CPython 3.7 | ✅ | N/A | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| CPython 3.8 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| CPython 3.9 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| CPython 3.10¹ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| PyPy 3.7 v7.3 | ✅ | N/A | ✅ | N/A | ✅ | ✅ | ✅ | N/A | N/A |
¹ Available as a prerelease under a flag
- Builds manylinux, macOS 10.9+, and Windows wheels for CPython and PyPy
- Works on GitHub Actions, Azure Pipelines, Travis CI, AppVeyor, CircleCI, and GitLab CI
- Bundles shared library dependencies on Linux and macOS through auditwheel and delocate
- Runs your library's tests against the wheel-installed version of your library
See the cibuildwheel 1 documentation if you need to build unsupported versions of Python, such as Python 2.
Usage
cibuildwheel runs inside a CI service. Supported platforms depend on which service you're using:
| Linux | macOS | Windows | Linux ARM | |
|---|---|---|---|---|
| GitHub Actions | ✅ | ✅ | ✅ | ✅¹ |
| Azure Pipelines | ✅ | ✅ | ✅ | |
| Travis CI | ✅ | ✅ | ✅ | |
| AppVeyor | ✅ | ✅ | ✅ | |
| CircleCI | ✅ | ✅ | ||
| Gitlab CI | ✅ |
¹ Requires emulation, distributed separately. Other services may also support Linux ARM through emulation or third-party build hosts, but these are not tested in our CI.
cibuildwheel is not intended to run on your development machine. Because it uses system Python from Python.org on macOS and Windows, it will try to install packages globally - not what you expect from a build tool! Instead, isolated CI services like those mentioned above are ideal. For Linux builds, it uses manylinux docker images, so those can be done locally for testing in a pinch.
Example setup
To build manylinux, macOS, and Windows wheels on GitHub Actions, you could use this .github/workflows/wheels.yml:
name: Build
on: [push, pull_request]
jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, windows-2019, macOS-10.15]
steps:
- uses: actions/checkout@v2
# Used to host cibuildwheel
- uses: actions/setup-python@v2
- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.0.0
- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse
# to supply options, put them in 'env', like:
# env:
# CIBW_SOME_OPTION: value
- uses: actions/upload-artifact@v2
with:
path: ./wheelhouse/*.whl
For more information, including PyPI deployment, and the use of other CI services or the dedicated GitHub Action, check out the documentation and the examples.
Options
| Option | Description | |
|---|---|---|
| Build selection | CIBW_PLATFORM |
Override the auto-detected target platform |
CIBW_BUILD CIBW_SKIP |
Choose the Python versions to build | |
CIBW_ARCHS |
Change the architectures built on your machine by default. | |
CIBW_PROJECT_REQUIRES_PYTHON |
Manually set the Python compatibility of your project | |
CIBW_PRERELEASE_PYTHONS |
Enable building with pre-release versions of Python | |
| Build customization | CIBW_BUILD_FRONTEND |
Set the tool to use to build, either "pip" (default for now) or "build" |
CIBW_ENVIRONMENT |
Set environment variables needed during the build | |
CIBW_BEFORE_ALL |
Execute a shell command on the build system before any wheels are built. | |
CIBW_BEFORE_BUILD |
Execute a shell command preparing each wheel's build | |
CIBW_REPAIR_WHEEL_COMMAND |
Execute a shell command to repair each (non-pure Python) built wheel | |
CIBW_MANYLINUX_*_IMAGE |
Specify alternative manylinux Docker images | |
CIBW_DEPENDENCY_VERSIONS |
Specify how cibuildwheel controls the versions of the tools it uses | |
| Testing | CIBW_TEST_COMMAND |
Execute a shell command to test each built wheel |
CIBW_BEFORE_TEST |
Execute a shell command before testing each wheel | |
CIBW_TEST_REQUIRES |
Install Python dependencies before running the tests | |
CIBW_TEST_EXTRAS |
Install your wheel for testing using extras_require | |
CIBW_TEST_SKIP |
Skip running tests on some builds | |
| Other | CIBW_BUILD_VERBOSITY |
Increase/decrease the output of pip wheel |
These options can be specified in a pyproject.toml file, as well; see configuration.
Working examples
Here are some repos that use cibuildwheel.
| Name | CI | OS | Notes |
|---|---|---|---|
| scikit-learn | The machine learning library. A complex but clean config using many of cibuildwheel's features to build a large project with Cython and C++ extensions. | ||
| Matplotlib | The venerable Matplotlib, a Python library with C++ portions | ||
| MyPy | MyPyC, the compiled component of MyPy. | ||
| psutil | Cross-platform lib for process and system monitoring in Python | ||
| scikit-image | Image processing library. Uses cibuildwheel to build and test a project that uses Cython with platform-native code. | ||
| twisted-iocpsupport | A submodule of Twisted that hooks into native C APIs using Cython. | ||
| cmake | Multitagged binary builds for all supported platforms, using cibw 2 config configuration. | ||
| websockets | Library for building WebSocket servers and clients. Mostly written in Python, with a small C 'speedups' extension module. | ||
| pyzmq | Python bindings for zeromq, the networking library. Uses Cython and CFFI. | ||
| aiortc | WebRTC and ORTC implementation for Python using asyncio. |
ℹ️ That's just a handful, there are many more! Check out the Working Examples page in the docs.
Legal note
Since cibuildwheel repairs the wheel with delocate or auditwheel, it might automatically bundle dynamically linked libraries from the build machine.
It helps ensure that the library can run without any dependencies outside of the pip toolchain.
This is similar to static linking, so it might have some licence implications. Check the license for any code you're pulling in to make sure that's allowed.
Changelog
v2.0.0 🎉
16 July 2021
- 🌟 You can now configure cibuildwheel options inside your project's
pyproject.toml! Environment variables still work of course. Check out the documentation for more info. - 🌟 Added support for building wheels with build, as well as pip. This feature is controlled with the
CIBW_BUILD_FRONTENDoption. - 🌟 Added the ability to test building wheels on CPython 3.10! Because CPython 3.10 is in beta, these wheels should not be distributed, because they might not be compatible with the final release, but it's available to build for testing purposes. Use the flag
--prerelease-pythonsorCIBW_PRERELEASE_PYTHONSto test. (#675) This version of cibuildwheel includes CPython 3.10.0b4. - ⚠️ Removed support for building Python 2.7 and Python 3.5 wheels, for both CPython and PyPy. If you still need to build on these versions, please use the latest v1.x version. (#596)
- ✨ Added the ability to build CPython 3.8 wheels for Apple Silicon. (#704)
- 🛠 Update to the latest build dependencies, including Auditwheel 4. (#633)
- 🛠 Use the unified pypa/manylinux images to build PyPy (#671)
- 🐛 Numerous bug fixes & docs improvements
v1.12.0
22 June 2021
- ✨ Adds support building macOS universal2/arm64 wheels on Python 3.8.
v1.11.1
28 May 2021
- ✨ cibuildwheel is now part of the PyPA!
- 📚 Minor docs changes, fixing links related to the above transition
- 🛠 Update manylinux pins to the last version containing Python 2.7 and 3.5. (#674)
v1.11.0
1 May 2021
- 📚 Lots of docs improvements! (#650, #623, #616, #609, #606)
- 🐛 Fix nuget "Package is not found" error on Windows. (#653)
- ⚠️ cibuildwheel will no longer build Windows 2.7 wheels, unless you specify a custom toolchain using
DISTUTILS_USE_SDK=1andMSSdk=1. This is because Microsoft have stopped distributing Visual C++ Compiler for Python 2.7. See this FAQ entry for more details. (#649) - 🐛 Fix crash on Windows due to missing
whichcommand (#641).
v1.10.0
22 Feb 2021
- ✨ Added
manylinux_2_24support. To use these new Debian-based manylinux images, set your manylinux image options tomanylinux_2_24. - 🛠 On macOS, we now set
MACOSX_DEPLOYMENT_TARGETin before runningCIBW_BEFORE_ALL. This is useful when usingCIBW_BEFORE_ALLto build a shared library. - 🛠 An empty
CIBW_BUILDoption is now the same as being unset i.e,*. This makes some build matrix configuration easier. (#588) - 📚 Neatened up documentation - added tabs to a few places (#576), fixed some formatting issues.
That's the last few versions.
ℹ️ Want more changelog? Head over to the changelog page in the docs.
Contributing
For more info on how to contribute to cibuildwheel, see the docs.
Everyone interacting with the cibuildwheel project via codebase, issue tracker, chat rooms, or otherwise is expected to follow the PSF Code of Conduct.
Maintainers
- Joe Rickerby @joerick
- Yannick Jadoul @YannickJadoul
- Matthieu Darbois @mayeut
- Henry Schreiner @henryiii
Credits
cibuildwheel stands on the shoulders of giants.
- ⭐️ @matthew-brett for matthew-brett/multibuild and matthew-brett/delocate
- @PyPA for the manylinux Docker images pypa/manylinux
- @ogrisel for wheelhouse-uploader and
run_with_env.cmd
Massive props also to-
- @zfrenchee for help debugging many issues
- @lelit for some great bug reports and contributions
- @mayeut for a phenomenal PR patching Python itself for better compatibility!
- @czaki for being a super-contributor over many PRs and helping out with countless issues!
- @mattip for his help with adding PyPy support to cibuildwheel
See also
If you'd like to keep wheel building separate from the package itself, check out astrofrog/autowheel. It builds packages using cibuildwheel from source distributions on PyPI.
Another very similar tool to consider is matthew-brett/multibuild. multibuild is a shell script toolbox for building a wheel on various platforms. It is used as a basis to build some of the big data science tools, like SciPy.