How to Check Python Version on Windows/Linux/Mac

How to Check Python Version : In this tutorial we will see how to get the version of python that is installed in our operating system via command prompts or directly from a script.
Overview
Python is the most widely used language in the world today. It is mainly used to develop applications, websites or in data analysis and machine learning. With these different applications, it is often necessary to install a specific version of python so that the libraries used can work correctly. So we will see how to determine the version of python installed on the OS.
Prerequisites
To get the python version, we need access to a terminal. To do this here is how to do it on each operating system :
- Windows: Win+R -> type powershell -> press Enter
- Linux: Ctrl+Alt+T, Ctrl+Alt+F2
- MacOS: Finder -> Applications -> Utilities -> Terminal
Python Versioning
The versions comply with a very specific standard. Python production-ready releases are versioned in the following syntax:
MAJOR.MINOR.MICRO
- MAJOR: Python currently has two major versions that are not fully compatible with each other. These are versions 2 and 3
- MINOR: These versions provide new functionalities to the main version (for example version 3.7 has seen the arrival of an API C called Thread Local Storage for the local storage of threads).
- MICRO: The micro versions contain bug fixes and slight improvements.
So version 3.7.2 has 3 as Major version,7 as Minor version and 2 as Micro version.
Check Python Version Windows
By default on windows, python is not installed on the operating system so you must first install python yourself. Once you have installed python on your machine, open Powershell and do the following command:
python ––version
If you have installed python correctly you will get the following result:
Python 3.7.2
Note: You can also use the python command -V or python -VV since python version 3.6 which is the same as –version
You can also type directly in the windows search bar if you want to get only the major and minor version of python like this:

As you can see I have version 3.7 installed on my Windows computer.
Check Python Version Linux
On most linux distributions (like Ubuntu, Debian) python is installed by default on the system. To check the install version use the following command:
python ––version
The result is as follows:
Python 3.7.2
Check Python Version MacOS
In general, python is already installed on MacOS. To get the python version, type the following command:
python ––version
Python 3.7.2
Check the Python version in the script
Instead of using the command line in a terminal, it may be necessary to fetch the python version from a script. There are two python modules available to get the current version of python:
- the sys module
- the platform module
The advantage is that these modules are available on any operating system so you will be able to use the codes used in this tutorial. These functions are useful if for example we want to modify the processing depending on the version of python installed.
Python version using sys.version
sys.version allows you to get the version of python mainly. It returns a string of characters:
import sys
print(sys.version)
Output:
3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)]
As you can see, the installed version is 3.7.6
Check Python version using sys.version_info
the sys module provides a second way to get the python version with sys.version_info. The main advantage of this method is that it returns a tuple with MAJOR, MINOR and MICRO versions:
import sys
print(sys.version_info)
print("Major version : " + str(sys.version_info[0]))
print("Minor version : " + str(sys.version_info[1]))
print("Micro version : " + str(sys.version_info[2]))
print("Release : " + str(sys.version_info[3]))
print("Serial : " + str(sys.version_info[4]))
Output :
sys.version_info(major=3, minor=7, micro=6, releaselevel=’final’, serial=0)
Major version : 3
Minor version : 7
Micro version : 6
Release : final
Serial : 0
Python version using platform.python_version()
The platform.python_version() function returns a string that returns the python version. Here is the syntax :
import platform
print(platform.python_version())
Output:
3.7.6
Python version using platform.python_version_tuple()
This function returns a tuple in the form (Major,Minor,Micro). Each element is an integer and not a string. Here’s the syntax:
import platform
print(platform.python_version_tuple())
print("Major version : " + str(platform.python_version_tuple()[0]))
print("Minor version : " + str(platform.python_version_tuple()[1]))
print("Micro version : " + str(platform.python_version_tuple()[2]))
Output:
(‘3’, ‘7’, ‘6’)
Major version : 3
Minor version : 7
Micro version : 6
What are the Different Python Versions
Here is the list of the different versions released to date:
- Python 3.8.3, documentation released on 13 May 2020.
- Python 3.8.2, documentation released on 24 February 2020.
- Python 3.8.1, documentation released on 18 December 2019.
- Python 3.8.0, documentation released on 14 October 2019.
- Python 3.7.7, documentation released on 10 March 2020.
- Python 3.7.6, documentation released on 18 December 2019.
- Python 3.7.5, documentation released on 15 October 2019.
- Python 3.7.4, documentation released on 08 July 2019.
- Python 3.7.3, documentation released on 25 March 2019.
- Python 3.7.2, documentation released on 24 December 2018.
- Python 3.7.1, documentation released on 20 October 2018.
- Python 3.7.0, documentation released on 27 June 2018.
- Python 3.6.10, documentation released on 18 December 2019.
- Python 3.6.9, documentation released on 02 July 2019.
- Python 3.6.8, documentation released on 24 December 2018.
- Python 3.6.7, documentation released on 20 October 2018.
- Python 3.6.6, documentation released on 27 June 2018.
- Python 3.6.5, documentation released on 28 March 2018.
- Python 3.6.4, documentation released on 19 December 2017.
- Python 3.6.3, documentation released on 03 October 2017.
- Python 3.6.2, documentation released on 17 July 2017.
- Python 3.6.1, documentation released on 21 March 2017.
- Python 3.6.0, documentation released on 23 December 2016.
- Python 3.5.8, documentation released on 29 October 2019.
- Python 3.5.7, documentation released on 18 March 2019.
- Python 3.5.6, documentation released on 8 August 2018.
- Python 3.5.5, documentation released on 4 February 2018.
- Python 3.5.4, documentation released on 25 July 2017.
- Python 3.5.3, documentation released on 17 January 2017.
- Python 3.5.2, documentation released on 27 June 2016.
- Python 3.5.1, documentation released on 07 December 2015.
- Python 3.5.0, documentation released on 13 September 2015.
- Python 3.4.10, documentation released on 18 March 2019.
- Python 3.4.9, documentation released on 8 August 2018.
- Python 3.4.8, documentation released on 4 February 2018.
- Python 3.4.7, documentation released on 25 July 2017.
- Python 3.4.6, documentation released on 17 January 2017.
- Python 3.4.5, documentation released on 26 June 2016.
- Python 3.4.4, documentation released on 06 December 2015.
- Python 3.4.3, documentation released on 25 February 2015.
- Python 3.4.2, documentation released on 4 October 2014.
- Python 3.4.1, documentation released on 18 May 2014.
- Python 3.4.0, documentation released on 16 March 2014.
- Python 3.3.7, documentation released on 19 September 2017.
- Python 3.3.6, documentation released on 12 October 2014.
- Python 3.3.5, documentation released on 9 March 2014.
- Python 3.3.4, documentation released on 9 February 2014.
- Python 3.3.3, documentation released on 17 November 2013.
- Python 3.3.2, documentation released on 15 May 2013.
- Python 3.3.1, documentation released on 7 April 2013.
- Python 3.3.0, documentation released on 29 September 2012.
- Python 3.2.6, documentation released on 11 October 2014.
- Python 3.2.5, documentation released on 15 May 2013.
- Python 3.2.4, documentation released on 7 April 2013.
- Python 3.2.3, documentation released on 10 April 2012.
- Python 3.2.2, documentation released on 4 September 2011.
- Python 3.2.1, documentation released on 10 July 2011.
- Python 3.2, documentation released on 20 February 2011.
- Python 3.1.5, documentation released on 9 April 2012.
- Python 3.1.4, documentation released on 11 June 2011.
- Python 3.1.3, documentation released on 27 November 2010.
- Python 3.1.2, documentation released on 21 March 2010.
- Python 3.1.1, documentation released on 17 August 2009.
- Python 3.1, documentation released on 27 June 2009.
- Python 3.0.1, documentation released on 13 February 2009.
- Python 3.0, documentation released on 3 December 2008.
- Python 2.7.18, documentation released on 20 April 2020
- Python 2.7.17, documentation released on 19 October 2019
- Python 2.7.16, documentation released on 02 March 2019
- Python 2.7.15, documentation released on 30 April 2018
- Python 2.7.14, documentation released on 16 September 2017
- Python 2.7.13, documentation released on 17 December 2016
- Python 2.7.12, documentation released on 26 June 2016.
- Python 2.7.11, documentation released on 5 December 2015.
- Python 2.7.10, documentation released on 23 May 2015.
- Python 2.7.9, documentation released on 10 December 2014.
- Python 2.7.8, documentation released on 1 July 2014.
- Python 2.7.7, documentation released on 31 May 2014.
- Python 2.7.6, documentation released on 10 November 2013.
- Python 2.7.5, documentation released on 15 May 2013.
- Python 2.7.4, documentation released on 6 April 2013.
- Python 2.7.3, documentation released on 9 April 2012.
- Python 2.7.2, documentation released on 11 June 2011.
- Python 2.7.1, documentation released on 27 November 2010.
- Python 2.7, documentation released on 4 July 2010.
- Python 2.6.9, documentation released on 29 October 2013.
- Python 2.6.8, documentation released on 10 April 2012.
- Python 2.6.7, documentation released on 3 June 2011.
- Python 2.6.6, documentation released on 24 August 2010.
- Python 2.6.5, documentation released on 19 March 2010.
- Python 2.6.4, documentation released on 25 October 2009.
- Python 2.6.3, documentation released on 2 October 2009.
- Python 2.6.2, documentation released on 14 April 2009.
- Python 2.6.1, documentation released on 4 December 2008.
- Python 2.6, documentation released on 1 October 2008.
- Python 2.5.4, documentation released on 23 December 2008.
- Python 2.5.3, documentation released on 19 December 2008.
- Python 2.5.2, documentation released on 21 February 2008.
- Python 2.5.1, documentation released on 18 April 2007.
- Python 2.5, documentation released on 19 September 2006.
- Python 2.4.4, documentation released on 18 October 2006.
- Python 2.4.3, documentation released on 29 March 2006.
- Python 2.4.2, documentation released on 28 September 2005.
- Python 2.4.1, documentation released on 30 March 2005.
- Python 2.4, documentation released on 30 November 2004.
- Python 2.3.5, documentation released on 8 February 2005.
- Python 2.3.4, documentation released on 27 May 2004.
- Python 2.3.3, documentation released on 19 December 2003.
- Python 2.3.2, documentation released on 3 October 2003.
- Python 2.3.1, documentation released on 23 September 2003.
- Python 2.3, documentation released on 29 July 2003.
- Python 2.2.3, documentation released on 30 May 2003.
- Python 2.2.2, documentation released on 14 October 2002.
- Python 2.2.1, documentation released on 10 April 2002.
- Python 2.2p1, documentation released on 29 March 2002.
- Python 2.2, documentation released on 21 December 2001.
- Python 2.1.3, documentation released on 8 April 2002.
- Python 2.1.2, documentation released on 16 January 2002.
- Python 2.1.1, documentation released on 20 July 2001.
- Python 2.1, documentation released on 15 April 2001.
- Python 2.0.1, documentation released on 22 June 2001.
- Python 2.0, documentation released on 16 October 2000.
- Python 1.6, documentation released on 5 September 2000.
- Python 1.5.2p2, documentation released on 22 March 2000.
- Python 1.5.2p1, documentation released on 6 July 1999.
- Python 1.5.2, documentation released on 30 April 1999.
- Python 1.5.1p1, documentation released on 6 August 1998.
- Python 1.5.1, documentation released on 14 April 1998.
- Python 1.5, documentation released on 17 February 1998.
- Python 1.4, documentation released on 25 October 1996.
Summary
As you can see, there are several methods to retrieve the versions of python installed in your operating system. Here is a summary of the different methods available:
Commands | How | Examples |
python --version orpython -V orpython -VV | Terminal | 3.7.6 |
import sys sys.version | String | ‘3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)]’ |
import sys sys.version_info | Tuple | sys.version_info(major=3, minor=7, micro=6, releaselevel=’final’, serial=0) |
import platfom platform.python_version() | String | ‘3.7.6’ |
import platfom platform.python_version_tuple() | Tuple | (‘3’, ‘7’, ‘6’) |
Comments
Leave a comment