How to check Python’s version from command line and in script

This post will introduce you useful ways to check what version of Python is running.

  • Python’s version can be check on the command line with --version-V-VV
  • Python’s version can be check in script with sysplatform

Check version on the command line

Commands below can be used if both Python 2 and 3 are installed on your system and the default running one is Python 2. python --version prints out the current running version.

python --version
>> Python 2.7.17

python -V
>> Python 2.7.17

python3 --version
>> Python 3.6.9

python3 -V
>> Python 3.6.9

Check version in script

 sys and platform module 2 default libraries which can be used to get the version of Python that is actually running.

They are used in the situation where you don’t know which Python are powering your app. So you need to add a version check in the app’s script to make sure.

import sys
import platform

>> 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)]

>> sys.version_info(major=3, minor=6, micro=9, releaselevel='final', serial=0)

>> 3.6.9
>> ('3', '6', '9')

Leave a Comment

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.