How To Check The Python Version In Linux

7 min read

Introduction

When working with Linux, one of the first things developers and system administrators need to verify is the Python version installed on the system. Knowing the exact version helps ensure compatibility with libraries, scripts, and the operating system itself. That said, whether you are setting up a new development environment, updating packages, or troubleshooting a script, being able to quickly check the Python version is an essential skill. This article walks you through the most common commands and methods for checking Python version in Linux, explains why version awareness matters, and provides troubleshooting tips for typical scenarios you might encounter Practical, not theoretical..

How to Check Python Version in Linux

Linux offers several straightforward ways to determine which Python version is currently available. Below are the most widely used commands, each with a brief explanation of what it does and when you might prefer one over the others Easy to understand, harder to ignore..

Using python3 --version

The python3 command is the standard way to invoke the Python 3 interpreter on most modern Linux distributions. Running python3 --version prints the version number directly to the terminal Nothing fancy..

python3 --version
# Output example: Python 3.10.12

When to use it: This is the go‑to command if you have Python 3 installed and want a quick, one‑line answer. It works on Ubuntu, Debian, Fedora, CentOS, Arch, and many other distros without any extra configuration.

Using python --version

On some systems, the python command points to the Python 3 interpreter (especially after installation packages like python3 create a symlink). If you run python --version, you’ll see the same output as with python3.

python --version
# Output example: Python 3.9.5

When to use it: Use this if your scripts or shebang lines reference python and you want to confirm that the default python points to the desired version. If python instead points to Python 2, you’ll see a different version number, which can be useful for diagnosing version mismatches.

Checking version via python3 -V

The -V flag is a short form of --version. It behaves identically to --version but is often preferred for scripting because it reduces the number of characters you need to type.

python3 -V
# Output example: Python 3.11.2

Why use -V: In automated environments (like Bash scripts or CI pipelines), the shorter flag can make the command more concise while delivering the same result Practical, not theoretical..

Using sys.version in a Python Script

If you need detailed version information programmatically—such as when writing a setup script or a diagnostic tool—you can query Python’s own internal data structures. Create a temporary script and run it:

python3 -c "import sys; print(sys.version)"
# Output example:
# 3.10.12 (main, Sep 13 2023, 13:45:12) [GCC 11.2.0]

The output includes the full version string, build information, and even the compiler used. On the flip side, you can also extract specific parts (major, minor, micro) using sys. version_info Less friction, more output..

python3 -c "import sys; print('.'.join(map(str, sys.version_info[:3])))"
# Output example: 3.10.12

When to use it: This method is ideal when you need version details beyond just the numeric version, such as checking the exact build or determining if a feature introduced in a specific micro‑release is available.

Checking All Installed Python Variants

Linux often ships with multiple Python installations (e., python3.On the flip side, 8, python3. 9, python3.Which means g. 10).

ls /usr/bin/python* | grep -E 'python[0-9\.]+
Newest Stuff

New Picks

Along the Same Lines

Round It Out With These

Thank you for reading about How To Check The Python Version In Linux. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home