How To Find Python Version?


I want to run some python scripts but want to learn version of the python installed on the system. How can I do that? This works almost all operating systems from Windows to Linux, from Mac OS to Bsd.

Get Version Of Default Python Interpreter

We can get default python interpreter version like below. As we know that if the version of python is not specified the default python interpreter will be called.

$ python -V

OR

$ python --version
Get Version Of Default Python Interpreter
Get Version Of Default Python Interpreter

We can see from output that current or default Python interpreter version is 2.7

Get Python2 Exact Version

We can get Python2 exact version like below

$python2 -V 
Python 2.7.12+ 

$python2 --version 
Python 2.7.12+

Get Python3 Exact Version

We can get Python2 exact version like below

$python3 -V 
Python 3.5.2+ 

$python3 --version 
Python 3.5.2+
Get Python3 Exact Version
Get Python3 Exact Version

Using sys.version Information

Python provides version attribute in sys module. We can use this attribute in order to get Python version interactively or programatically.

import sys
print(sys.version)
Using sys.version Information
Using sys.version Information

Update Python Interpreter Version

If we want to update Python interpreter we generally use package managers provided by the distributions.

Ubuntu, Debian, Mint, Kali

$ sudo apt update python

Fedora, CentOS, RedHat

$ sudo yum update python

OR

$ sudo dnf update python

How To Find Python Version? Infografic

How To Find Python Version? Infografic
How To Find Python Version? Infografic

LEARN MORE  How To Use Linux df Command with Examples?

Leave a Comment