How to Check Python Version in Linux, Mac, & Windows

Guide of How to Check Python Version in Linux, Mac, & Windows – Python is a popular programming language. Like many other programming languages, there can be several different versions organized by release date. Certain applications may require a specific version of Python.

Prerequisites

Access to a command-line/terminal window:

Linux: Ctrl-Alt-T, Ctrl-Alt-F2
Windows: Win+R > type powershell > Enter/OK
MacOS: Finder > Applications > Utilities > Terminal

How to Check Python Version in Linux

Most modern Linux distributions come with Python pre-installed.

To check the version installed, open a terminal window and enter the following:

python --version

How to Check Python Version in Windows

Most out-of-the-box Windows installations do not come with Python pre-installed. However, it is always a good idea to check.

Open Windows Powershell, and enter the following:

python --version

If you have Python installed, it will report the version number.

Alternately, use the Windows Search function to see which version of Python you have:

Press the Windows key to start a search, then type Python. The system will return any results that match. Most likely a match will show something similar to:

Python 3.7 (32-bit)

How to Check Python Version in MacOS

If using a macOS, check the version by entering the following command in the terminal:

python -version

How to Check Python Version in Script

When writing an application, before running the code you can check by simply using the following script to check the correct version.

import sys

if not sys.version_info.major == 3 and sys.version_info.minor >= 6:

    print("Python 3.6 or higher is required.")

    print("You are using Python {}.{}.".format(sys.version_info.major, sys.version_info.minor))

    sys.exit(1)

Conclusion

You should now have a solid understanding of how to check for the version installed in several different operating systems. Python is a powerful programming language, thus it’s important to understand its different versions.

That’s all for this article if you have any confusion contact us through our website or email us at [email protected] or by using LinkedIn.

Suggested Articles:

  1. NPM Versioning Guide
  2. How to create a virtual environment in Python?
  3. How to Connect Python with Database

Leave a Comment