Just add this to the start of your script:
import sys
assert sys.version_info >= (3, 5, 2), "Python version too low."
Or if you prefer without assert
:
import sys
if not sys.version_info >= (3, 5, 2):
raise EnvironmentError("Python version too low.")
Or little bit more verbosely, but this will actually inform the user what version they need:
import sys
MIN = (3, 5, 2)
if not sys.version_info >= MIN:
raise EnvironmentError(
"Python version too low, required at least {}".format('.'.join(str(n) for n in MIN)))
Example output:
Traceback (most recent call last):
File "main.py", line 6, in <module>
"Python version too low, required at least {}".format('.'.join(str(n) for n in MIN)))
OSError: Python version too low, required at least 3.5.2
The specified minimum version tuple can be as precise as you want. These are all valid:
MIN = (3,)
MIN = (3, 5)
MIN = (3, 5, 2)