Conditional dependency with Python Wheels

python, python-2.7, python-3.x, python-wheel

Solution

As of Wheel 0.24.0, this is support using `extra_require`. For instance

setup(
    ...,
    extras_require={':python_version=="2.6"':: ['ipaddr']},
    ...
)

This is documented in the "Defining Conditional Dependencies" of the Wheel documentation and follows PEP 426.

Problem

I have a Python package that I would like to make into a wheel. On Python 2, the package uses the `ipaddr` library. On Python 3, it uses the built-in `ipaddress` library. For the `sdist` package, I check the `sys.version_info` in `setup.py` to set the requirements based on the Python version. Unfortunately, this does not seem to work with wheels. Is it possible to do a conditional dependency based on the Python version with a wheel?

Original source