You are on page 1of 2

7/17/23, 12:51 PM How to Check Python Version in Ubuntu

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
print(sys.version.split()[0])

Using version_info to print major version:

import sys
print(sys.version_info.major)

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

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

SQL Server

MySQL Administration

https://www.configserverfirewall.com/ubuntu-linux/check-python-version-ubuntu/ 1/2
7/17/23, 12:51 PM How to Check Python Version in Ubuntu

Web Hosting Guide

Unix

Debian Linux

Ubuntu Firewall

Privacy Policy

https://www.configserverfirewall.com/ubuntu-linux/check-python-version-ubuntu/ 2/2

You might also like