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.
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.
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.
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.
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.
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.
I’ve written about the EU Cyber Resilience Act (CRA) on our Canonical blog a few…
Today, IBM announced the launch of their latest server: the new IBM LinuxONE Emperor 5.…
Welcome to the Ubuntu Weekly Newsletter, Issue 890 for the week of April 27 –…
Singapore | May 27, 2025 | Full-day event How do you build robust, performant edge…
Kolla Ansible provides production-ready containers (here, Docker) and deployment tools for operating OpenStack clouds. This…
This public beta enables the full Ubuntu Desktop experience on the Qualcomm Dragonwing™ QCS6490 and…