Skip to Content

3 Ways to check Python 3 Version

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

3 Ways to check Python Version

Commands Example Output
python3 –version or
python3 -V or
python3 -VV
Python 3.7.2
import sys
sys.version
3.7.2 (tags/v3.7.2: 9a3ffc0492, Dec 23 2018,
23:09:28)[MSC v.1916 64 bit (AMD64)]’
sys.version_info sys.version_ info (major= 3, minor= 7, micro= 2, releaselevel= ‘final’, serial= 0)
import platform
platform.python_version()
‘3.7.2’

Check the Python 3 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 the Python version with sys module

It is useful for checking which version of Python is running in an environment where multiple versions of Python are installed. Even though we thought Python3 was running, there was a case where Python2 was running, so if something goes wrong, check it once.

$ 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())”

3.6.8

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

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