How to Check Your Python Version?
You can use the standard library sys module or platform module to get the version of Python that is actually running.
import sys
print(sys.version)

From command line
You can see which version of Python is installed on your OS using the command line .- python -V
(Note: capital 'V')

Which version of Python is running my script?
In Python 2.7 and later, the components of sys.version_info can also be accessed by name, so sys.version_info[0] is equivalent to sys.version_info.major and so on.
>>> import sys
>>> print(sys.version_info)
sys.version_info(major=3, minor=4, micro=3, releaselevel='final', serial=0)
>>> import sys
>>> print(sys.version.split(' ')[0])
3.4.3
Here, sys.version_info[0] is the major version number. sys.version_info[1] would give you the minor version number.
Platform Module in Python
Python defines an in-built module platform that provides system information. You can use the platform module to get the version of Python that is actually running.
>>> from platform import python_version
>>> print(python_version())
3.4.3
Python is being updated regularly with new features and supports. There are lots of update in Python versions, started from 1994 to current release. Python Implementation started on December, 1989 and reached version 1.0 in January 1994. Like many other programming languages, there can be several different versions organized by release date.
Python Versions
The standard version scheme is designed to encompass a wide range of identification practices across public and private Python projects. A tuple containing the five components of the version number : major, minor, micro, releaselevel, and serial. All values except release level are integers; the release level is 'alpha', 'beta', 'candidate', or 'final'. The version_info value corresponding to the Python version 2.0 is (2, 0, 0, 'final', 0).Run the Python command-line interpreter:
- Open Command line: Start menu -> Run and type cmd
- Type: C:\Python34\python.exe

Here you can see, Python version is displayed on console immediately as you start interpreter from command line. The details are a string containing the version number of the Python interpreter plus additional information on the build number and compiler used.
From command line
You can check which version of Python is installed on your operating system using the command line using the following command.- C:\Python34> Python -c "print(__import__('sys').version)"

Check Python Version from your program
You can programmatically determine which version of Python is installed on the system where the Python script is running. For example, to check that you are running Python 3.x , use:
import sys
if sys.version_info[0] < 3:
raise Exception("You must be using Python 3")
Related Topics