Search code examples
pythonpippython-wheel

Pip install and platform specific wheels


How does pip install select wheels to install?

Say I've built multiple wheels for different platforms, and upload to PyPI does pip install <package> automatically install the correct wheel that matches the platform?

What happens if I've built a Linux specific wheel only and upload to PyPI, and someone on Windows/Mac trying to install it by running pip install <package>?


Solution

  • PIP follows the PEP 425 Use recommendations; this stipulates how a binary distribution wheel is selected.

    Specifically, pip install will only consider compatible wheels. A wheel compatible with a different platform is not going to be downloaded.

    If there are no compatible wheels, but there is a source distribution, then that source distribution is downloaded and compiled locally. If there are no compatible wheels, and no source distribution, installation fails.

    Wheels can also be built for pure python projects, at which point they are no longer platform specific; these are called universal wheels. If a project uses optional binary components they can choose to produce both platform-specific wheels (including the compiled binary components specific to a Python ABI version and platform), and a universal wheel with the optional compiled components excluded. An installer can then select the universal version if no compatible binary version is available for the current platform. This is not all that common however, as a universal wheel would be preferred over a source distribution!