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 sys.version_info < (3, 5, 2):
raise EnvironmentError("Python version too low.")
Or little bit more verbosely, but this will actually inform what version is needed:
import sys
MIN_VERSION = (3, 5, 2)
if sys.version_info < MIN_VERSION:
raise EnvironmentError(
"Python version too low, required at least {}".format(
'.'.join(str(n) for n in MIN_VERSION)
)
)
Example output:
Traceback (most recent call last):
File "main.py", line 6, in <module>
raise EnvironmentError(
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)