Check Python Version In Code: Require A Minimum

You can check for the Python version in your code, to make sure your users are not running your script with an incompatible version. All you need to do is import the module sys and use the sys.version_info function. Use this simple check:

import sys

if not sys.version_info > (2, 7):
   # berate your user for running a 10 year
   # python version
elif not sys.version_info >= (3, 5):
   # Kindly tell your user (s)he needs to upgrade
   # because you're using 3.5 features

Get certified with our courses

Learn Python properly through small, easy-to-digest lessons, progress tracking, quizzes to test your knowledge, and practice sessions. Each course will earn you a downloadable course certificate.

Leave a Comment