You can use Python sys module to check what version of Python is running your script as shown in the below example –
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import sys print(sys.version) ## Returns 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] print(sys.version_info) ## Returns sys.version_info(major=3, minor=7, micro=4, releaselevel='final', serial=0) v = sys.version print(v[0:5]) ## Returns 3.7.4 ## To ensure a script runs with a minimal version requirement ## of the Python interpreter add this to your code: assert sys.version_info >= (2, 5) |