Config Server Firewall

How to Check Python Version in Ubuntu

Python is such a popular scripting language and various useful programs included in Ubuntu are written in Python. Therefore, Ubuntu Linux comes with Python preinstalled.

To check the Python version, Open the command line interface and execute the following command:

python3 -V

If you automate stuff with Python, sometimes you will need to check the Python version in a Python script. For this, we use the sys module, which has the version and version_info objects to check the Python version.

import sys

Using version_info to print major version:

import sys

Python 3 is the default version in Ubuntu 20.04 LTS, although Python 2 is still available to install.

how to check python version in ubuntu

One can install Python 2, by running the apt install python2 command.