Logo

How to Check Python Version in Linux, Windows, And macOS: A Comprehensive Guide

Try this guide with our instant dedicated server for as low as 40 Euros

Check Python Version

Python is a versatile programming language developers use for everything from web development, automation, data analysis, and machine learning. The flexibility of the language comes from a wide range of native and third-party packages that bring in functionalities missing from the core language features.

While these packages are a great way of extending Python’s capabilities and saving development time by reusing pre-written and tested code, you should be aware of the challenge of version compatibility between the installed Python version and the packages.

Not all packages are compatible with all Python versions. It is, therefore, critical that you should check Python version on your system before you install any packages for your projects.

This detailed guide will explain how to check the Python version on your system. Since Python is available on all popular operating systems, we will cover the process of checking Python versions on Linux, Windows, and macOS to help users regardless of their OS.

However, first, let us go into the details of what makes Python a fantastic programming language on all OS platforms.

Table Of Content

  1. What Makes Python Such An Amazing Programming Language?
    1. Emphasis on Readability
    2. Simplicity and Clarity
    3. Versatility and Adaptability
    4. Interactivity and Swift Prototyping
    5. Portability and Cross-Platform Compatibility
    6. Robust Standard Library
    7. Community and Open Source Values
    8. Object-Oriented Programming (OOP)
    9. Ease of Learning (and Teaching)
  2. How to Check Python Version
    1. The Prerequisites
    2. How to Check Python Version in Linux
    3. How to Check Python Version in Windows
    4. How to Check Python Version in MacOS
    5. Verifying Python Version Within the Code
  3. Conclusion
  4. FAQs

What Makes Python Such An Amazing Programming Language?

Guido van Rossum officially released Python in 1991. The primary objective behind the move was to create a programming language known for its readability, simplicity, and ease of comprehension. Guido van Rossum’s vision for Python emphasized clear and understandable code, enabling programmers to craft components using fewer lines of code than other languages.

Python is the language of choice for many proprietary and open-source projects today. Here are a couple of reasons behind its popularity. 

Emphasis on Readability

Python has a clean and easily understandable syntax that uses indentation and whitespace to define code blocks. The code is easy to read because of the distinct separation between blocks and sub-blocks. 

Simplicity and Clarity

Python advocates a straightforward and lucid programming style. The idea is to keep everything simple to speed up the development process and improve codebase maintenance. 

Versatility and Adaptability

Python is versatile and flexible, making it a good fit across diverse domains such as web development, scientific computing, data analysis, artificial intelligence, machine learning, and automation.

Interactivity and Swift Prototyping

Python supports an interactive mode, facilitating quick experimentation and testing of code snippets. Developers use this feature to check out ideas and speed up prototyping and initial component development.

Portability and Cross-Platform Compatibility

Python is platform-independent, enabling seamless execution of the same codebase across various operating systems with minimal or no modifications.

Robust Standard Library

Python boasts an extensive standard library with pre-built modules and functions, catering to a wide range of typical development challenges. Developers do not have to reinvent the wheel every time they need to solve a problem because there is often a package or code snippet for it. 

Community and Open Source Values

Python adheres to an open-source development model, fostering collaboration, knowledge sharing, and community-driven contributions. Over the years, developers and enthusiasts have created a dynamic and supportive global community around the language.

Object-Oriented Programming (OOP)

Python is founded on the principles of object-oriented programming, facilitating code organization into reusable and modular structures. This significantly enhances code reusability and maintainability.

Ease of Learning (and Teaching)

An essential aspect of developing Python was to make it easily learnable and teachable. As a result, it is the popular choice as the first programming language in many CS 101 courses. 

How to Check Python Version

Now that you have the background information about Python, let’s jump right into how you can check Python version on your system. As mentioned earlier, we’ll cover Linux, Windows, and macOS platforms. Here’re the prerequisites: 

The Prerequisites

You’ll need:

  • A system running either Linux, Windows, or macOS
  • Access to a terminal or command prompt
  • Administrative privileges or rights

 

How to Check Python Version in Linux

Follow these steps to check the Python version on a Linux-based operating system:

  • Open a terminal window.
  • Type one of the following commands and press Enter:

python --version

Or

python3 --version

The output will display the installed Python version.

How to Check Python Version in Linux

 

How to Check Python Version in Windows

Follow these steps to find out the Python version in a Windows environment:

  • Open the Command Prompt.
  • Enter the command:

python --version

The Python version will appear in the following line.

How to Check Python Version in Windows

 

How to Check Python Version in MacOS

If you’re using macOS, simply follow these steps to check Python version:

  • Open the terminal.
  • Enter one of the following commands:

python --version

Or

python3 --version

The response will show the version installed on your macOS system.

How to Check Python Version in MacOS

 

Verifying Python Version Within the Code

When developing an application, developers should implement a check to verify that the appropriate Python version is available. This preemptive check can avert potential crashes and discrepancies due to version conflicts.

To implement a Python version check, you can use the following code snippet that checks whether Python 3.6 or higher is available on the target system:

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)

If the required Python version is absent, the script will issue an alert and inform the user about the required Python version. By editing the values in the first IF statement, you can easily modify this code snippet to check for your preferred version.

python 2 vs python 3

Conclusion

Identifying the Python version installed on your system is a fundamental operational requirement that every developer should know how to fulfill. Whether you are using Linux, macOS, or Windows, the techniques outlined in this article will check Python version.

If you’re looking for a robust server for your Python projects, RedSwitches offers the best dedicated server pricing and delivers instant dedicated servers, usually on the same day the order gets approved. Whether you need a dedicated server, a traffic-friendly 10Gbps dedicated server, or a powerful bare metal server, we are your trusted hosting partner.

 

FAQs

Q. How do I check which version of Python is installed on my Windows computer?

To check the Python version on Windows, you can open the Windows Command Prompt and type python –version or python -V.

Q. How can I check which version of Python is installed on my MacOs?

To check the Python version on a Mac, you can open the terminal and type python –version or python -V.

Q. How do I check the Python version on Linux?

To check the Python version on Linux, you can open the terminal and type python –version or python -V.

Q. Can I have multiple versions of Python installed on my computer?

Yes, you can have multiple versions of Python installed on your computer. Each version will have its own Python interpreter.

Q. How do I check the Python version using a Python script?

To check the Python version using a Python script, create a Python file and add the following snippet:
import sys
print(sys.version)

When you execute this snippet, it will print the available Python version.

Q. How can I easily check the version of Python 3 installed on my computer?

To easily check the version of Python 3 installed on your computer, you can open the command prompt or terminal and type python3 –version or python3 -V.

Q. How can I display the Python version number using Python code?

To display the Python version number using Python code, you can open a text editor and write the following code in a Python file:
import platform
print(platform.python_version())

Try this guide with our instant dedicated server for as low as 40 Euros