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

Python is one of the most famous programming languages ​​as it is used in various fields such as web development, machine learning, data analysis and software testing just to name a few.

Python was released on February 20, 1991 by Guido van Rossum. When Rossum created Python, he also read Monty Python's Flying Circus, the script for the popular BBC comedy series. Thus, he settled on the name as he considered the new language to be mysterious and unique.

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

Here are some of the things you can do with Python.

  • Web development. Python is used in back-end development (processes that users don't see). Flask and Django are examples of frameworks that are widely used in API and backend development.
  • Automation or scripting. If there is work that you do all the time, Python can help you automate it. Beginners as well as experts can use Python to automate various tasks such as sending emails, searching for data on the web, sorting data, and downloading.
  • Data analysis and machine learning. Python has become one of the most popular programming languages ​​among data scientists. Data analysts can now create data visualizations, perform complex statistical calculations, manipulate and analyze, and more.
  • Software testing and prototyping. In a software development setup, Python can be used for bug tracking, testing, and build control. Developers can automate tests and validations of new systems and applications using Python.
  • Business applications. The business world is wide and some of the things that might come to mind are e-commerce applications, customer management systems and ERP just to name a few. A typical business environment will require applications that are easy to read, extensible, and scalable. Python offers such a solution through its platforms such as Tryton.
  • It is universal. If you have interacted with other languages, you may have noticed that some of them have one or only two use cases. However, Python has over five use cases and yet its performance is unmatched.
  • Has several libraries and modules. There are many libraries and modules created by third parties to extend the capabilities of Python. For example, you can use Django for server side web development.
  • Python is simple. This programming language mimics natural language making it suitable even for beginners.
  • Large and active community. Programming can be tricky at times. However, having a large and supportive community means there are people you can always turn to if you get stuck.
  • Open source. Python is free to use and redistribute. This way, engineers can customize existing code, distribute it, and build different solutions/applications with it.

Python 2 vs Python 3: Difference

The Python programming language has undergone significant changes in over 3 decades of its existence. One reason you might want to check your Python version is to determine if you're using Python 2 or Python 3 to make sure you're building bug-free solutions, whether you're a developer or an expert on data.

Python 2 and Python 3 are the main versions in the Python world. There is still debate about which is better. Let's check the difference between them;

Python 2

Python 2 was introduced in 2000 by BeOpen Python Labs. This version was intended to make it easier to learn Python.

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

Python 3

Python 3 was released in 2008. This version was created to fix fundamental flaws in Python 2. Python 3 got rid of the repetitive modules and constructs that were in previous versions of Python.

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

The introduction of this version attracted a large mass of the scientific community, for example, neuroscience. The introduction of the NumPy library made Python a competitor to Matlab and R, and accelerated its adoption in data science and machine learning. At the time of writing, the current version of Python is Python 3.11.1.

ComparisonPython 2Python 3Year of release20002008SupportSupport ended in 2020Python 3 development and support is still ongoingBackward compatibilityPython 2 code can be ported to Python 3 with some modificationsPython 3 code cannot be run on Python 3ApplicationMainly used in DevOpsPython is multi-purpose and applicable in software development, data science and much moreKeyword "Print"Print is not considered a function, but an operator. Print is considered a function, not a statement.

Prerequisites for checking the Python version

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

  • Windows: Win+R > введите powershell > Enter/OK
  • Linux: Ctrl-Alt-T, Ctrl-Alt-F2
  • macOS: Finder > Applications > Utilities > Terminal

Since you now 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 backwards incompatible. Python 2 and Python 3 are different pieces of software. So this means that code written in Python 2 may not work as expected in Python 3.

When you check the version of Python on your machine, it will be presented in three sections separated by a dot.

  • Major version
  • minor version
  • Micro version

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

Python 3.7.1 is compatible with Python 3.8.10 because they are in the same major version (3). However, Python 2.7 is not compatible with Python 3.8.

Check Python version on Windows

Open Windows PowerShell by doing the following;

Win+R > введите powershell > Enter/OK

Now you can go ahead and type this on the command line

python-version

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

Check Python version on Linux

Most modern Linux operating systems come pre-installed with Python.

Use the keyboard shortcut Ctrl+Alt+T to open a command prompt on your Linux 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 will most likely get something like this

Check Python Version on MacOS

You can quickly access your terminal on 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 Python 3 installed, you will get output close to this

Check python version in script

It's important to check the Python version in your script when writing code to avoid incompatibilities and crashes when you run your code.

This check is very important when you have more than one version of Python installed on your PC.

Whether you are using Windows, Linux or macOS, you can use this command to test your script.

import sysprint (sys.version)

What happens if two different versions of Python are installed on the same machine and you run the above commands?

Python 2 and Python 3 can run simultaneously on your PC. The reason for this is that you may have applications that use Python 2 while others are built with Python 3.

To check if there are two versions of Python 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 output close to this screenshot.

Conclusion

Python still powers some of your favorite social media platforms like Instagram, entertainment sites like Spotify, and ride management platforms like Uber. If you need to build platforms that create similar or better platforms, Python should be one of your considerations.

Now you can conveniently check the Python version regardless of the operating system you are using. Even though most of them are moving to Python 3, you will still encounter applications built with Python 2. The good news is that Python has different frameworks that you can use to build different applications.

Related posts