Home » Programming » Python » Check Python Version

Check Python Version (Windows, Linux & macOS)

This tutorial explains how to check the version of Python that is installed on your system. The commands work on Windows, Linux & macOS, and with Python2 or Python3.

Python is an incredibly popular and powerful programming language worldwide for everything from website development, content aggregation tools, link shortening, and writing scripts, to data analysis, virtual assistants, and machine learning. There are various versions available with different release dates, so how do you know which version is running on your machine? Here’s a quick guide on how to check the Python version on any macOS, Linux, or Windows system.

Why Version Knowledge Is Important

It’s important to know which version of Python is running, especially if you run into incompatibility errors or crashes. Not all types and versions of Python are compatible with one another and some applications will require a particular version of the programming language. In this case, you’ll need to have the correct Python version for the application to work correctly.

It’s also helpful to know if you’re planning to update any software, as Python requires you to manually navigate to the downloads page to upgrade. There are no automatic updates, as downloading Python is essentially about teaching your system how to understand and use Python.

Finding the actual version that you are using is pretty straightforward. We’ll cover two ways to do this: via a terminal, sometimes known as the command-line, and programmatically using a script. First, we’ll look at the output, to understand the version number you’ll see displayed.

Understanding the Command-Line Output

You first need to open a command-line prompt. This is different for each system:

  • Windows : Win+R > type ‘powershell’ > hit Enter
  • Linux: Ctrl-Alt-T (Ubuntu 18.04 has a simple launcher for navigating to the shell by typing the first couple of letters, such as for ‘shell’, ‘command’ or ‘terminal’).
  • MacOS : Open a Finder window > Go to Applications > Utilities > Open Terminal

Two of the most popular versions of Python are 2.7x and 3.7x. Python 2.7 and Python 3.7 are different programs and they are not compatible with one another. You, therefore, need to know which version is running because software written for one of these versions won’t normally work correctly in the other.

To understand the version displayed, you’ll need to know what the numbers refer to. They typically take an A.B.C format, which indicates the Major, Minor & Micro Versions of the application. A is the Major version, which is for major changes in the programming language. B is incremented for moderate changes to the programming language. C is the revision number, which is for smaller changes such as patches and bug-fixes.

Minor releases are generally compatible with one another, whereas major releases may not be. For instance, 3.6.1 should be compatible with the later version 3.7.1, where the Minor number (7 in this case) is different, but the Major number (3) is the same.

It’s worth noting that Python 2 will receive no new published patches and updates after 2020. However, Python 3 comes with utilities to translate any code from Python 2 to the latest Python 3, which is helpful considering how many developers use version 2.7. If you want to write code that runs with Python 2 and Python 3, the future module can be utilized.

Checking The Version via Terminal

Linux

Python is usually pre-installed in contemporary Linux systems. In the terminal window, type:

python —version

This will report back the version, such as Python 3.7.9.

Windows

If Python is installed, you can use Windows Powershell to find the version. Type:

python —version

Windows Search will also show the Python version running, just type ‘Python’ in the search bar.

macOS

In the macOS terminal, type:

python —version

Alternatively, the following commands will also work:

python -V
python -VV

You might find that just the version is returned, but there may be additional data. If this occurs, just scan the information until you find ‘python’ with a number following it to indicate the version.

Identifying Multiple Python Versions

If one system runs both Python2 and Python3, you can search for these separately as most systems will record Python2 as simply python and Python 3 as python3.

Check Python 2.x.x:

python —version

Check Python 3.x.x:

python3 —version

Checking The Version Via Script

Every Python version makes the sys module available, so sys.version_info will tell you the major, minor, and micro details. If you’re about to write an application, checking the version beforehand can help to prevent any incompatibilities or problems from occurring.

Checking Python this way also enables you to check which version is running on another machine. This can be helpful if you want to ensure that the app you want to use will run safely without crashing on any device.

Python may seem complex at first, but discovering the version number is actually very simple and potentially very useful.

SHARE:
Photo of author
Author
My name is Stefan, I'm the admin of LinuxScrew. I am a full-time Linux/Unix sysadmin, a hobby Python programmer, and a part-time blogger. I post useful guides, tips, and tutorials on common Linux and Programming issues. Feel free to reach out in the comment section.

Leave a Comment