install_requires based on python version

iTayb picture iTayb · Jan 13, 2014 · Viewed 13.3k times · Source

I have a module that works both on python 2 and python 3. In Python<3.2 I would like to install a specific package as a dependency. For Python>=3.2.

Something like:

 install_requires=[
    "threadpool >= 1.2.7 if python_version < 3.2.0",
 ],

How can one make that?

Answer

unholysampler picture unholysampler · Sep 18, 2015

Use environment markers:

install_requires=[
    'threadpool >= 1.2.7; python_version < "3.2.0"',
]

Setuptools specific usage is detailed in their documentation. The syntax shown above requires setuptools v36.2+ (change log).