Require minimum Python version in setup.py

Almost everyone uses setuptools.setup in their setup.py. The field python_requires allows fine-grained control of which versions of Python are supported. Let’s explain the use of this by example. We assume that setup.py is structured like

from setuptools import setup, find_packages

setup(name='JoesProg',
      packages=find_packages(),
      python_requires='>=3.5',
      ...
      )

NOTE: You must install packages (including those local on your hard drive e.g. a Git repo) with

pip install -e .

NOT

python setup.py develop

as the latter ignores python_requires. Both methods use *.egg-link in site-packages/ so that you’re always using what’s in your ~/code directory, not a frozen .egg version.

Python ≥ a version

This is by far the most common use case, to avoid confusion from the few users still on Python 2. Many Python users have at least Python 3.5, and Python 3.6 has been widely available and supported for some time. Many of my programs have

python_requires='python>=3.5'

or even

python_requires='python>=3.6'

Python ≤ a version

Let’s say you have one of those rare programs that doesn’t run on Python 3. You can forbid Python 3 from installing it by setting

python_requires='<3'

or since we know Python 2.7 is the last Python 2 version

python_requires='<=2.7'

Inclusive Range of Python versions

Let’s say your program only works for Python 2.6 and 2.7.

python_requires='>=2.6,<=2.7'

Even more options found in the reference below.

Notes

specification reference

Leave a Comment