How to Check Python Version in Various OS

How to check python version is one of the most searched questions among python. The simple answer is to run python -V in your command line terminal or shell.

Objective

This article will provide you with information on how to check the Python version on your operating system. This can be useful when installing applications that require a specific version of Python.

We’ll also show you how to programmatically determine what version of Python is installed on the system where the Python script is running. For example, when writing Python scripts, you’ll need to determine whether the script supports the version of Python installed on the user’s machine.

Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python’s design philosophy emphasizes code readability with its notable use of significant whitespace. Wikipedia

How Python Versioning is Done

Python production-ready releases are versioned in the following scheme:

MAJOR.MINOR.MICRO

For example, in Python 3.6.8, 3 is a major version, 1 is a minor version, and 2 is a micro version.

  • MAJOR – Python has two major versions that are not fully compatible: Python 2 and Python 3. For example, 3.5.73.7.2, and 3.8.0 are all part of the Python 3 major version.
  • MINOR – These releases are bringing new features and functions. For example, 3.6.63.6.7, and 3.6.8 are all part of the Python 3.6 minor version.
  • MICRO – Typically, the new micro versions contain various bug fixes and improvements.

How to Check Python Version in Windows

Windows do not have Python pre-installed. Therefore the default installer on python.org is x86, which may not be the architecture of your PC. So the processor type information is available in Windows Settings. However, if your system is x64 processor-based, you need to get the x86-64 installer from Python. Official Python Website.

How to Check Python Version in Windows 10

  1. Open Windows Search. If you don’t already see a search box in the taskbar, select the magnifying glass or circle next to 
Image titled Windowsstart.png

 , or press ⊞ Win+S.

How to Check Python Version Windows 10

2. Type python into the search bar. A list of matching results will appear.

How to Check Python Version Windows

Find the version in the first line. It’s the number right after the word “Python” at the top-left corner of the window (e.g. 2.7.14).

How to Check Python Version in Windows 7

Steps to check the Python version on your Windows 7 operating system:

  1. Open the Command Prompt Application: Press the Windows key or go to the Windows icon in the taskbar to open the start screen. After that in the search box, type CMD. Press enter.
  2. Execute the command: type python -V or python --version  and press enter.
  3. So finally the Python version appears in the next line below your command.

How to Check Python Version in Linux

Most modern Linux distributions come with Python pre-installed in it.

To check the version installed, open a terminal window and entering the following:

Python 2

$ /usr/bin/python -V
OR
/usr/bin/python --version
Python 2.7.15rc1

Python 3

$ /usr/bin/python3 -V
OR
/usr/bin/python3 --version
Python 3.6.5
  • # – requires given Linux commands to be executed with root privileges either directly as a root user or by use of sudo command
  • $ – requires given Linux commands to be executed as a regular non-privileged user

Your system may have both Python 2 and Python 3 version installed. The first hint about the python version your system has installed is by checking for installed python binary executable:

$ ls /usr/bin/python*
/usr/bin/python  /usr/bin/python2  /usr/bin/python2.7  /usr/bin/python3  /usr/bin/python3.6  /usr/bin/python3.6m  /usr/bin/python3m

Another path the Python binaries can be installed in is /usr/local/bin/. As you can see our system has both Python 2 and Python 3 versions installed.

How to Check Python Version in Mac OS

Python is probably already installed on your system. To check if it’s installed, go to Applications>Utilities and select Terminal. (You can also press command-spacebar, type terminal, and then press Enter.)

Find out which version of Python is installed by issuing the command python --version:

$ python --version
Python 2.7.5

If you see something like this, Python 2.7 is your default version. You should also see if you have Python 3 installed:

$ python3 --version
Python 3.7

How to Check Python Version in CentOS

1. Check the Python version :

[root@vps ~]# python --version
Python 2.7.5

2. After that enter the python command line :

[root@vps ~]# python
Python 2.7.5 (default, Jun 17 2014, 18:11:42)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

3. To exit, run the following command :

>>> quit()

How to Check Python Version in Raspberry Pi

In Rasberry Pi, to check the Python version in the command line, run python with “-V” option:
python -V
python3 -V
pypy -V

To check running python version in python code:

import sys
print(sys.version)

How to Check Python Version in.vimrc

First, checking if you have Python in your Vim and which version you are using. In addition, it returns a version similar to how Vim does it with its version. So 204 is the result for Python 2.4, 207 for Python 2.7 and so on.

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Check python version if available
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("python")
    python import vim; from sys import version_info as v; vim.command('let python_version=%d' % (v[0] * 100 + v[1]))
else
    let python_version=0
endif

Now we can make plugins/bundles depending on versions:

if python_version >= 205
    " Ultisnips requires Vim 2.5 or higher due to the with_statement
    Bundle 'SirVer/ultisnips'
else
    Bundle "MarcWeber/vim-addon-mw-utils"
    Bundle "tomtom/tlib_vim"
    Bundle "garbas/vim-snipmate"
endif

How to Check Python Version in Script

Use the following code snippet to check for the correct version of Python:

import sys
if not sys.version_info.major == 3 and sys.version_info.minor >= 6:

    print("Python 3.6 or higher is required.")

    print("You are using Python {}.{}.".format(sys.version_info.major, sys.version_info.minor))

    sys.exit(1)

When this script runs, it will test to see if Python 3.7 is installed on the system. However if not, it will send a notification and displays the current Python version.

Check Python Version using sys. version

However, sometimes you need to check Python version programmatically, from within your Python script. Then your best bet is to use the sys module:

greys@srv:~ $ python -c "import sys; print(sys.version)"
2.7.16 (default, Oct 10 2019, 22:02:15)
[GCC 8.3.0]

The output should be a named tuple like this one:

Out[2]: sys.version_info(major=3, minor=5, micro=1, releaselevel='final', serial=0)

How to Check Python Version Programmatically

Python 2 and Python 3 are fundamentally different. The code that is written in Python 2.x may not work in Python 3.x.

In addition, the sys module that is available in all Python versions provides system-specific parameters and functions. Therefore, sys.version_info allows you to determine the Python version installed on the system. Above all, it is a tuple that contains the five version numbers: major, minor, micro, release level, and serial.

import sys

if not sys.version_info.major == 3 and sys.version_info.minor >= 5:
    print("This script requires Python 3.5 or higher!")
    print("You are using Python {}.{}.".format(sys.version_info.major, sys.version_info.minor))
    sys.exit(1)

If you run the script using Python version less than 3.5 it will produce the following output:

This script requires Python 3.5 or higher!
You are using Python 2.7.

How to Check Python Version Using python_version() Function

Another function to check the python version is python_version() a function. But first, we need to import platform module like below.

import platform  
platform.python_version()

List of all Python versions:

  • Python Beta Version
  • Python 1.0
  • Python 2.0
  • Python 3.0

Python Beta Version Release Date

Since an initial version of Python was released in 1991. So this was 0.9.0 and not a full number 1, as it was not ready for prime time yet. These versions were released on the following schedule:

  • Python 0.9.0 – February 20, 1991
  • Python 0.9.1 – February 1991
  • Python 0.9.2 – Autumn, 1991
  • Python 0.9.4 – December 24, 1991
  • Python 0.9.5 – January 2, 1992
  • Python 0.9.6 – April 6, 1992
  • Python 0.9.8 – January 9, 1993
  • Python 0.9.9 – July 29, 1993

Python 1.0 Version-Release Date

The first official version of Python was launched in 1994.

  • Python 1.0 – January 1994
  • Python 1.2 – April 10, 1995
  • Python 1.3 – October 12, 1995
  • Python 1.4 – October 25, 1996
  • Python 1.5 – December 31, 1997
  • Python 1.6 – September 5, 2000

Python 2.0 Version-Release Date

Released in 2000, Python 2.0 not only offered a whole host of new features, but the new version was transitioned to a community-based, collaborative open-source language.

  • Python 2.0 – October 16, 2000
  • Python 2.1 – April 15, 2001
  • Python 2.2 – December 21, 2001
  • Python 2.3 – July 29, 2003
  • Python 2.4 – November 30, 2004
  • Python 2.5 – September 19, 2006
  • Python 2.6 – October 1, 2008
  • Python 2.7 – July 4, 2010

Python 2.7 was the last release in the 2.x series. In November 2014, it was announced that Python 2.7 would be supported until 2020, but users were encouraged to move to Python 3 as soon as possible.

Python 3.0 Version-Release Date

Python 3.0 is also known as “Python 3000” or “Py3K,” and it is the current major version of Python.

  • Python 3.0 – December 3, 2008
  • Python 3.1 – June 27, 2009
  • Python 3.2 – February 20, 2011
  • Python 3.3 – September 29, 2012
  • Python 3.4 – March 16, 2014
  • Python 3.5 – September 13, 2015
  • Python 3.6 – December 23, 2016
  • Python 3.7 – June 27, 2018
  • Python 3.8 – Oct 14, 2019
  • Python 3.9 – Oct 5, 2019

Also Read:

Python Remove Duplicates From List
Python Print Without Newline
Learn Python the Hard Way Review PDF
How to Get a Data Science Internship With No Experience
Python Map

Conclusion

So we have tried to cover How to Check Python Version in Various OS and it is easy, just remember to do this once in a while – perhaps by placing a reminder on your calendar.

In conclusion, if you have still some problem regarding How to Check Python Version you can Comment down below.

Happy Coding!

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments