How to Check Python Version on Ubuntu 26.04

Knowing how to check the Python version on Ubuntu 26.04 is essential for developers, system administrators, and anyone working with Python-based applications. Different projects require specific Python versions, and verifying your installed version ensures compatibility with libraries, frameworks, and scripts. This guide covers multiple methods to check your Python version on Ubuntu 26.04, from simple terminal commands to programmatic approaches within scripts.

In this tutorial you will learn:

  • How to check Python version using terminal commands
  • How to interpret Python version numbering
  • How to distinguish between Python 2 and Python 3 installations
  • How to check Python version programmatically within scripts
Abstract illustration representing Python version checking on Ubuntu Linux with terminal window and Python logo elements
Checking Python version on Ubuntu 26.04

Software Requirements

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu 26.04 Resolute Raccoon
Software Python 3.x (pre-installed)
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user
TL;DR
To check your Python version on Ubuntu 26.04, run python3 --version in the terminal.

Quick Steps to Check Python Version
Step Command/Action
1. Check Python 3 version python3 --version
2. Check detailed version info python3 -V
3. Check version in Python shell python3 -c "import sys; print(sys.version)"

Check Python Version on Ubuntu 26.04 Using the Terminal

The most straightforward way to check your Python version on Ubuntu 26.04 is through terminal commands. Ubuntu 26.04 comes with Python 3 pre-installed, making it immediately available for version checking.

  1. Using the –version flag: The standard method to display the Python version.
    $ python3 --version

    This command outputs the version number in a simple format, such as Python 3.13.0.

  2. Using the -V flag: A shorter alternative that produces identical output.
    $ python3 -V

    Both --version and -V are functionally equivalent.

  3. Using the python command: On Ubuntu 26.04, the python command may point to Python 3.
    $ python --version

    If this command returns an error, Python 3 is accessible only via the python3 command.

Terminal showing python3 --version outputting Python 3.13.11 and python --version showing command not found with suggestions to install python3 or python-is-python3 package on Ubuntu 26.04
Using python3 –version to check the installed Python version on Ubuntu 26.04

Understanding Python Version Output

Python version numbers follow semantic versioning with three components: major, minor, and micro versions. Understanding this numbering scheme helps you determine compatibility with various packages and frameworks.

When you run python3 --version, the output displays as Python X.Y.Z, where:

  • X (Major version): Indicates significant changes that may break backward compatibility. Python 3 introduced changes incompatible with Python 2.
  • Y (Minor version): Represents new features added in a backward-compatible manner. For example, Python 3.12 added new syntax features not present in 3.11.
  • Z (Micro version): Contains bug fixes and security patches without new features.

For more detailed version information, use the Python interpreter directly:

$ python3 -c "import sys; print(sys.version)"

This command displays additional details including the build date and compiler information. You can also check the version tuple programmatically:

$ python3 -c "import sys; print(sys.version_info)"

The output shows a named tuple with major, minor, micro, release level, and serial components. This format is particularly useful when you need to perform version comparisons in scripts.

Terminal showing python3 -c command with sys.version_info output displaying major=3, minor=13, micro=11, releaselevel=final, serial=0 on Ubuntu 26.04
Displaying detailed Python version information using sys.version_info

Check Python 2 vs Python 3 Versions

Ubuntu 26.04 ships with Python 3 as the default and recommended Python version. However, some legacy applications may require Python 2, which is no longer maintained but can still be installed for compatibility purposes.

To check if Python 2 is installed on your system:

$ python2 --version

If Python 2 is not installed, you will see an error message indicating the command was not found. You can install Python 2 if your project specifically requires it, though this is discouraged for new development.

IMPORTANT
Python 2 reached end-of-life on January 1, 2020. For new projects, always use Python 3. Only install Python 2 when absolutely necessary for legacy application support.

To see all Python versions installed on your system, you can check the available binaries:

$ ls -la /usr/bin/python*

This command lists all Python-related executables, showing you which versions are available and how the symbolic links are configured.

If you need to work with Python 2 for legacy projects, refer to our guide on how to use Python 2 on Ubuntu 26.04.

Terminal showing ls -la /usr/bin/python* output displaying python3 symlink pointing to python3.13 and the python3.13 executable on Ubuntu 26.04
Viewing installed Python executables in /usr/bin directory

Check Python Version in Scripts

When writing Python scripts that require specific versions, you can programmatically check and enforce version requirements. This approach prevents runtime errors caused by version incompatibilities.

  1. Basic version check using sys module: Access version information within your script.
    import sys
    print(f"Python version: {sys.version}")
    print(f"Version info: {sys.version_info}")

    The sys module provides comprehensive version details accessible at runtime.

  2. Enforce minimum version requirement: Exit gracefully if the Python version is insufficient.
    import sys
    
    if sys.version_info < (3, 10):
        sys.exit("This script requires Python 3.10 or higher")
    
    # Your script continues here

    This pattern is useful for scripts distributed to systems with varying Python installations.

  3. Check version using platform module: An alternative method providing similar information.
    import platform
    print(platform.python_version())

    The platform module returns the version as a simple string.

For projects using virtual environments or multiple Python versions, checking the version ensures your script runs with the correct interpreter. Additionally, if you work with Python packages, you may want to install pip to manage dependencies effectively.

Terminal showing a Python script using platform.python_version() to check version, with output displaying 3.13.11 on Ubuntu 26.04
Using the platform module in a Python script to check the installed version

For comprehensive documentation on Python version handling and the sys module, consult the official Python sys module documentation.

Conclusion

Checking your Python version on Ubuntu 26.04 is a fundamental skill for any developer or system administrator. Whether you use the simple python3 --version command or implement programmatic version checks in your scripts, understanding your Python environment ensures smooth development and deployment. Ubuntu 26.04 provides Python 3 by default, aligning with modern Python development practices. Remember to verify version compatibility before installing packages or running scripts that may have specific version requirements.

Frequently Asked Questions

  1. Why does the python command not work on Ubuntu 26.04? Ubuntu 26.04 may not have the python command symlinked by default. Use python3 instead, as this is the recommended and pre-installed Python version. If you need the python command to work, you can install the python-is-python3 package using sudo apt install python-is-python3.
  2. What Python version comes pre-installed with Ubuntu 26.04? Ubuntu 26.04 Resolute Raccoon ships with Python 3.13 as the default Python version. This version is installed as part of the base system since many system tools depend on Python. You can verify this by running python3 --version immediately after installation.
  3. How do I check which Python version a specific script will use? Check the shebang line at the top of the script. A line like #!/usr/bin/env python3 indicates Python 3, while #!/usr/bin/python2 specifies Python 2. You can also run which python3 to see the exact path of the Python interpreter that will be used when you execute commands.