3 Ways to Check Python Version in Linux

Table of Contents

In this article, we will cover how to check the Python version in 3 ways.


Check Python Version Commands Example Output
python –version or
python -V or
python -VV
Python 3.6.8
import sys

3.6.8 (default,  Mar 18 2021,  08:58:41) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]

import sys
sys. version_info (major= 3,  minor=6, micro=8,  releaselevel = ‘final’, serial = 0)
import platform

Check Python version with OS command

Execute the python or python3 command with the –version or -V option on the command prompt.

In some environments, the Python2.x series is assigned to python command, and the Python3.x series is assigned to python3 command.

  • $ python –version
    Python 2.7.15
  • $ python -V
    Python 2.7.15
  • $ python3 –version
    Python 3.7.0
  • $ python3 -V
    Python 3.7.0

Check Python version with sys module

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

3.6.8 (default, Mar 18 2021, 08:58:41)

[GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]

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

sys.version_info(major=3, minor=6, micro=8, releaselevel=’final’, serial=0)


Check the Python version with platform module

platform.python_version() returns a string major.minor.patchlevel.

It is useful when we want to get the version number as a simple string.


$ python3 -c “import platform; print(platform.python_version())”


$ python3 -c “import platform; print(platform.python_version_tuple())”

(‘3’, ‘6’, ‘8’)

Table of Contents

Share on facebook
Share on twitter
Share on linkedin

You might also like