English English French French Spanish Spanish German German
Geekflare is supported by our audience. We may earn affiliate commissions from buying links on this site.
Share on:

How to Check Python Version in Windows, Linux, and macOS [2023]

Check-Python-Version-in-Windows-Linux-and-macOS-1
Invicti Web Application Security Scanner – the only solution that delivers automatic verification of vulnerabilities with Proof-Based Scanning™.

Python is one of the most famous programming languages as it is used across different domains such as web development, machine learning, data analytics, and software testing, to mention just a few.  

Python was released on February 20, 1991, by Guido van Rossum. As Rossum was creating Python, he was also reading “Monty Python’s Flying Circus”, a script of a popular BBC comedy series. He thus settled on the name as he considered the new language mysterious and unique.

This general-purpose programming language has a wide variety of users, and you may have interacted with it unknowingly through the movie recommendations on Netflix. Python is also used in the creation of software that controls self-driving cars. 

Some of the things you can do with Python are

  • Web development. Python is used in backend development (the processes that users don’t see). Flask and Django are examples of frameworks that are widely used in the development of APIs and backend servers. 
  • Automation or scripting. If there is a job that you find yourself performing repeatedly, Python can help you automate it. Beginners, as well as experts, can use Python to automate various tasks such as sending emails, finding data online, sorting data, and downloading. 
  • Data analysis and machine learning. Python has become one of the most sought programming languages by data scientists. Data analysts can now create data visualizations, conduct complex statistical calculations, manipulate & analyze and so much more. 
  • Software testing and prototyping. In a software development setup, Python can be used in bug tracking, testing, and build control. Developers can automate tests and checks on new systems and apps using Python. 
  • Business applications. The business world is wide, and some of the things that may come to mind are e-commerce applications, customer management systems, and ERP, to mention a few. A typical business setting will need applications that are easily readable, extensible, and scalable. Python offers such a solution through its platforms, such as Tryton. 
  • It is versatile. If you have interacted with other languages, you may have noted that some have a single or just two use cases. However, Python has more than five use cases, and still, its performance is unmatched. 
  • Has multiple libraries and modules. There exist tons of libraries and modules created by third parties to expand on the use cases of Python. For instance, you can use Django for server-side web development. 
  • Python is simple. This programming language mimics the natural language, making it suitable for even beginners. 
  • Large and active community. Programming can be challenging at times. However, the presence of a big and supportive community means that there are people you can always turn to when you get stuck. 
  • Open-source. Python is free to use and distribute. Engineers can thus tweak existing code, redistribute and create various solutions/ applications with it. 

Python 2 and Python 3: Difference

Python programming language has evolved a lot over the more than 3 decades that it has been in existence. One of the reasons you may want to check the Python version is to determine if you are using Python 2 or Python 3 to ensure that you build bug-free solutions, irrespective of whether you are a developer or a data expert. 

Python 2 and Python 3 are the major versions in the Python world. There has been an ongoing debate on which is better. Let us check the difference between the two;

Python 2

Python 2 was introduced in 2000 by BeOpen Python Labs. This version was intended to make learning Python easy. 

It was through Python 2 that the technical details of the Python Enhancement Proposal (PEP) were implemented. In January 2020, Python 2 was sunsetted, which means it will no longer be updated with security patches, new features, and bug fixes. 

Python 3

Python 3 was released in 2008. This version was created to rectify the fundamental Python 2’s flaws. Python 3 did away with duplicate modules and constructs that were in the previous Python versions. 

The removal of duplicate tools with the introduction of Python 3 meant some of the code in Python 2 was incompatible with Python 3. Luckily, Python released 2to3, a tool that reviews and automatically converts Python 2 code to Python 3 syntax. 

The introduction of this version attracted a big mass of the scientific community, such as those in neuroscience. The introduction of the NumPy library now posed Python as a competitor to Matlab and R and also accelerated its adoptions in data science and machine learning. At the time of writing, the current version of Python is Python 3.11.1.

ComparisonPython 2Python 3
Year released20002008
SupportSupported stopped in 2020Development and support of Python 3 is still ongoing
Backward compatibilityWith some modifications, Python 2 codes can be ported to Python 3Python 3 code can’t be run on Python 3
ApplicationIt was mostly used in DevOpsPython is multipurpose and applicable in software engineering, data science, and so much more
“Print” keywordPrint is not considered a function but a statementPrint is considered a function and not a statement
Syntax complexityMore complicatedLess complicated
Storage of strings By default, strings are stored as ASCIIBy default, strings are stored as UNICODE

Prerequisites to check the Python Version

You can access the terminal window/ terminal using these commands on Windows, Linux, and macOS, respectively; 

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

Since now you know that there are two major versions of Python, we can go ahead and learn how to check the version on our local machines. 

Python 3 is backward incompatible. Python 2 and Python 3 are different pieces of software. It thus means that code written in Python 2 may not work as expected in Python 3. 

When you check the Python version on your machine, the version will be represented in 3 sections separated by a dot. 

  • The major version
  • The minor version
  • The micro version

For instance, if we take the Python version, Python 3.8.10, 3 is the major version, 8 is the minor version, and 10 is the micro version. The last section of the Python version represents the latest updates and patches. 

Python 3.7.1 is compatible with Python 3.8.10 as they belong to the same major version (3). However, Python 2.7 is not compatible with Python 3.8.

Check Python Version on Windows

Open Windows PowerShell using these steps;

Win+R > type powershell > Enter/OK

You can now go ahead and type this on the command line 

python --version

If Python is installed on your machine, the version will appear on the next line.

Windows

Check Python Version on Linux

Most modern Linux operating systems have Python pre-installed. 

Use the Ctrl+Alt+T shortcut to open the command line on your Linux-based machine. 

Use this command to print the Python version;

python3 --version

 Or 

python --version

The second command checks if Python 2 is installed

If Python 3 is installed, you are likely to get something like this

Linux-1

Check Python Version on MacOS

You can quickly access your terminal in MacOS using this shortcut;

Finder > Applications > Utilities > Terminal

Use this command to check the Python version;

python3 --version

 Or 

python --version

The second command checks if Python 2 is installed

If you have both Python 2 and 3 installed, you will get an output close to this

macOs-5-1

Check Python Version in the Script

It is important to check the Python version on your script when coding to avoid incompatibilities and crushes when you run the code. 

Such a check is very important when you have more than one Python version on your PC. 

Irrespective of whether you are using Windows, Linux, or macOS, you can use this command to check your script

import sys

print (sys.version)

What happens if the same machine has two different versions of Python installed and you run the above-mentioned commands?

Python 2 and Python 3 can run concurrently on your PC. The reason for this is that you may have some apps that are using Python 2 while others are created on Python 3. 

To check whether the two Python versions are on your PC, use these commands;

python3 --version

 Or 

python --version

The second command checks if Python 2 is installed

If both versions are present on macOS, you will get an output close to this screenshot

macOs-4-1

Conclusion

Python continues to power some of your favorite social media platforms, such as Instagram, entertainment sites, such as Spotify, and rides management platforms, such as Uber. If you need to create platforms creating similar or better platforms, Python should be one of your considerations. 

You can now comfortably check the Python version irrespective of the operating systems you are using. Even though most are shifting to Python 3, you will still come across apps created on Python 2. The good news is that Python has various frameworks that you can use to create different applications. 

You may also explore how to install Python 3 on CentOS, Ubuntu, and Windows.

Thanks to our Sponsors
More great readings on Development
Power Your Business
Some of the tools and services to help your business grow.
  • Invicti uses the Proof-Based Scanning™ to automatically verify the identified vulnerabilities and generate actionable results within just hours.
    Try Invicti
  • Web scraping, residential proxy, proxy manager, web unlocker, search engine crawler, and all you need to collect web data.
    Try Brightdata
  • Semrush is an all-in-one digital marketing solution with more than 50 tools in SEO, social media, and content marketing.
    Try Semrush
  • Intruder is an online vulnerability scanner that finds cyber security weaknesses in your infrastructure, to avoid costly data breaches.
    Try Intruder