Is there any way to tell setuptools or distribute to require a package on a specific platform?
In my specific case, I\'m using readline
, which comes as par
While the answer given by Martijn Pieters was totally valid at the time, Python packaging has changed a lot since then.
The preferred format to distribute packages is using wheels*. Using wheels it is not possible to run Python code during installation.
Wheel use metadata version two as specified in PEP 0427. Environment markers can be used to specify platform specific dependencies.
Setuptools allows to specify these environment markers as extras_require
keys. The following example script depends on pyreadline
for Windows systems and on pyxdg
for Linux distributions.
#!/usr/bin/env python
from setuptools import setup
setup(
name='spam',
version='0.0.1',
extras_require={
':sys_platform == "win32"': [
'pyreadline'
],
':"linux" in sys_platform': [
'pyxdg'
]
})
*Also release an sdist, so platforms which can't use wheel can still install your package.