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.
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 is equivalent to sys.version_info.major and so on.
Here, sys.version_info is the major version number. sys.version_info 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.
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: