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

Linux TLDR
Last Updated:
Reading time: 2 minutes

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.

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:

checking Python 2 version in linux

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:

checking Python 3 version in linux

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

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:

checking python version from python interpreter

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!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.

1 thought on “How to Check Python Version in Linux (via 3 Methods)”