31

How do I use python_requires classifier in setup.py to require Python 2.7.* or 3.2+?

I have tried many configurations, including this one: ~=2.7,==3,!=3.0,!=3.1,<4 but none have worked

wim
  • 338,267
  • 99
  • 616
  • 750
wolfy1339
  • 784
  • 2
  • 7
  • 23

1 Answers1

45

This argument for setuptools uses the PEP440 version specifiers spec, so you can ask for:

python_requires='>=2.7,!=3.0.*,!=3.1.*'

The commas , are equivalent to logical and operator.

Note that the metadata generated is only respected by pip>=9.0.0 (Nov 2016).

wim
  • 338,267
  • 99
  • 616
  • 750
  • 9
    See also the relevant [setuptools doc](https://setuptools.readthedocs.io/en/latest/setuptools.html?highlight=python_requires#new-and-changed-setup-keywords) and [PEP 345](https://www.python.org/dev/peps/pep-0345/). – Asclepius Jun 23 '17 at 00:53
  • 2
    See also: https://packaging.python.org/guides/distributing-packages-using-setuptools/#python-requires – 0 _ Feb 04 '19 at 21:46
  • Sadly, following the links shows that the "," is treated as `and`, so something like "`==2.7, >=3.9`" will never work. – Aaron D. Marasco May 11 '21 at 22:11