Categories: TutorialsUbuntu

How to Check Python Version in Linux (via 3 Methods)

Python is one of the most widely used programming languages that powers many popular web applications, AI/ML technologies, IoT devices, task automation, and many more.

Sponsored

Right now, Python 3 is the latest version, but if you are using an outdated system, you might be using an older version of Python, possibly Python 2, which is now deprecated.

Knowing the correct Python version is crucial, whether you are running a program that only works with a specific version or planning to start a Python project with the latest version.

In this quick guide, I’ll show you how to check the Python version in Ubuntu and other Linux distros from the command line.

How to Check Python Version in Linux (via 3 Methods)

There are multiple ways to find out the Python version from the command line; here I’ve provided you with the first two ways to identify if Python 2 or 3 is running on your Linux system, and the third method works for any Python version.

Method 1: Check Python 2 Version via Python Command

If you are running the older Python 2 version (which is now deprecated) on your Linux system, you can try running the “python” command with the “-V” or “–version” option to check its version information.

$ python -V

# OR

$ python --version

Output:

This method only works for Python 2, as Python 3 requires a different command, which you can find in the next section.

Method 2: Check Python 3 Version via Python Command

To check the Python 3 version information, you can try running the “python3” command with the “-V” or “–version” option.

$ python3 -V

# OR

$ python3 --version

Output:

This method works for any Linux distribution, as well as for Windows and macOS.

Sponsored

Method 3: Check Python Version via Python Interpreter

The previous two methods will help you find the Python version installed on your Linux system, but if you want to check the Python version in the interpreter (also known as the Python console) or within a Python script, you can do that too.

The “sys” and “platform” modules can help you check the installed Python version; the “sys” module provides detailed information, including the build number and date, while the “platform” module only prints the version.

You can use any one of them according to your needs, so when you’re ready, open your Python console or script and copy-paste any of the following Python snippets:

# Checking Python Version Using Sys Module
import sys
print(sys.version)

# Checking Python Version Using Platform Module
import platform
print(platform.python_version())

Output:

This method would work on any Linux distribution (such as Debian, Ubuntu, Red Hat, Fedora, Arch, Manjaro, etc.), as well as on Windows, macOS, or Raspberry Pi.

Final Word

Knowing the correct Python version is crucial to ensuring compatibility among the program, libraries, framework, and applications. This article shows you various methods to check the installed Python version on your Linux system, whether from the command line, the Python interpreter, or programmatically.

If you have any questions, feel free to ask them in the comments.

Till then, peace!

The post How to Check Python Version in Linux (via 3 Methods) appeared first on Linux TLDR.

Ubuntu Server Admin

Recent Posts

CRA compliance: Things IoT manufacturers can no longer do under the CRA (and what to do instead)

I’ve written about the EU Cyber Resilience Act (CRA) on our Canonical blog a few…

2 days ago

IBM LinuxONE 5 and Ubuntu Server, a great combination from day one

Today, IBM announced the launch of their latest server: the new IBM LinuxONE Emperor 5.…

3 days ago

Ubuntu Weekly Newsletter Issue 890

Welcome to the Ubuntu Weekly Newsletter, Issue 890 for the week of April 27 –…

3 days ago

Ubuntu IoT Day in Singapore – Unlock compliant and scalable innovation in edge AI

Singapore | May 27, 2025 | Full-day event How do you build robust, performant edge…

4 days ago

Kolla Ansible OpenStack Installation (Ubuntu 24.04)

Kolla Ansible provides production-ready containers (here, Docker) and deployment tools for operating OpenStack clouds. This…

7 days ago

Canonical announces first Ubuntu Desktop image for Qualcomm Dragonwing™ Platform with Ubuntu 24.04

This public beta enables the full Ubuntu Desktop experience on the Qualcomm Dragonwing™ QCS6490 and…

1 week ago