Check Python version

The quickest way to check the Python version is to run this command in the command line:

python --version

Another, and quicker way (note the capital v):

python -V

Both commands will work on all popular systems: Windows, Linux, and Mac.

More information

You can add another capital v, if you want more information, like the Python version, release date.

It will also display whether you use the 32-bit or 64-bit versions.

python -VV

Python versions

There are two major Python versions: Python 2 and Python 3 that are not fully compatible.

If both versions are installed on the machine you can check for Python 2 using this command:

python --version

or

python2 --version

If you want to check python3 version, use this command:

python3 --version

Check Python version inside the code

To check the version of Python interpreter inside the script you have to import the sys module first, and then display the Python version.

import sys
print(sys.version)

The print function will display this result:

3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)]

You can also display the system version info:

print(sys.version_info)

Result:

sys.version_info(major=3, minor=7, micro=2, releaselevel='final', serial=0)