When / where should I check the minimum version of Python?

This question tells me how to check the version of Python. For my package, I need at least Python 3.3:

MIN_VERSION_INFO = 3, 3

import sys
if not sys.version_info >= MIN_VERSION_INFO:
    exit("Python {}.{}+ is required.".format(*MIN_VERSION_INFO))

but where / when should this check happen?

I want to get the maximum possible error message for users installing via pip(sdist and wheel) or python setup.py install. Sort of:

$ pip -V
pip x.x.x from ... (Python 3.2)
$ pip install MyPackage
Python 3.3+ is required.

$ python -V
Python 3.2
$ python setup.py install
Python 3.3+ is required.
+4
source share
1 answer

, , , .

setup.py script, , . - __init__.py ( MAJOR-, ), , .

, : Python 2.6 unittest , , docstring, __all__.

__init__.py, , , docstring sys, . __init__.py.

+2

Source: https://habr.com/ru/post/1542495/


All Articles