How to Check Python Version

Check python version

To check the Python version on the command line, run:

python --version

Alternatively, you can run python -V or python -VV.

To obtain your Python version in a script, you can use the sys module:

import sys

print(sys.version)

Or the platform module:

import platform

print(platform.python_version())

How to Check Your Python Version Overview

The clearest way to figure out the Python version is running python --version on a command-line application. But there are other commands too.

Alternatively, you can use python -V too. This is just a shorthand for python --version.

To get more specific version information of Python3, run python3 -VV:

$ python3 -VV
Python 3.9.0 (default, Oct 27 2020, 14:15:17) 
[Clang 12.0.0 (clang-1200.0.32.21)]

This command gives you more detailed version information.

Notice, however, that this option was added to Python 3.6+. Running -VV on < Python 3.6 does not show the additional info.

Check Python Version in a Python Script

Now you know how to check your Python version on a command-line tool. But what if you want to check the version from a script directly?

No problem. There are four ways you can do it.

Use the Sys Module

To get the basic version information directly from a Python script, use the built-in sys module:

import sys

print(sys.version)

Output (example):

3.9.0 (default, Oct 27 2020, 14:15:17) 
[Clang 12.0.0 (clang-1200.0.32.21)]

Or if you want to get this info as a tuple, access the version_info property:

import sys

print(sys.version_info)

Output (example):

sys.version_info(major=3, minor=9, micro=0, releaselevel='final', serial=0)

Use the Platform Module

Another way to access the version information on a Python script is by using the platform module.

For example:

import platform

print(platform.python_version())

Output (example):

3.9.0

Or if you want to get the version info as a tuple:

import platform

print(platform.python_version_tuple())

Output (example):

('3', '9', '0')

Now you know all the ways you can get the version info about Python.

Next, let’s see system-specific guides on how to use command-line tools to get the version info.

How to Check Python Version on Any Environment

Here is a table that shows how to check the Python version on any environment:

EnvironmentMethod
Windows 10, Windows 71. Open CMD
2. Run python -V
Linux, macOS, Ubuntu1. Open Terminal
2. Run Python -V
Python Script,
Jupyter Notebook
import sys
print(sys.version)

If you are using Python3 and want to know its version, repeat the above steps but instead of typing python -V, type python3 -V. This returns the version info of your Python3. For example: Python 3.9.0.

Windows 10

Figure out the Python version on your Windows 10 OS with these steps:

  1. Open the Powershell by pressing the Windows key and typing in “powershell”. Press enter to launch the Powershell app.
  2. Type python --version into the Powershell window and hit enter.
  3. The version number appears below.

Windows 7

Figure out your Python version on Windows 7 OS with these steps:

  1. Open the command prompt by pressing the Windows key and typing in “command prompt”. Press enter to launch the Powershell app.
  2. Type python --version into the command propmpt window and hit enter.
  3. The version number appears below.

Mac

To see your Python version on Mac:

  1. Open up a Terminal window by hitting Command-Space and typing in “Terminal”
  2. Type python -V into the Terminal window and hit enter.
  3. As a result, you get the version number below your command.

Linux

To know the Python version on Linux, follow these three steps:

  1. Launch a terminal from your desktop’s application menu and you will see the bash shell.
  2. Type python --version into the bash shell and hit enter.
  3. The Python version appears below your command.

Ubuntu

To check the Python version on Ubuntu:

  1. Click on the dash icon on the Unity launcher (top-left).
  2. Type python --version into the dash window and hit enter.
  3. The Python version appears below your command.

Conclusion

Thanks for reading. I hope you found what you were looking for.

Happy coding!

Further Reading

50 Python Interview Questions and Answers

50+ Buzzwords of Web Development

Share on facebook
Facebook
Share on google
Google+
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on pinterest
Pinterest

Leave a Comment

Your email address will not be published.