Table of contents
1.
Introduction
2.
Check Python Version: Command-Line
2.1.
i) Windows
2.2.
ii) MacOS
2.3.
iii) Linux
3.
Check Python Version: Script
3.1.
i) Various information string: sys.version :
3.2.
ii) Tuple of version numbers: sys.version_info :
3.3.
iii) Version number string: platform.python_version() :
3.4.
iv) Tuple of version number strings: platform.python_version_tuple() :
4.
Check Python Version: Integrated Development Environments (IDE)
4.1.
i) Checking Python Versions in Visual Studio Code
4.2.
ii) Checking the Python version in PyCharm
5.
What are the Different Python Versions?
6.
How to Update Python version to the latest version?
7.
Upgrade Python on Windows:
8.
Upgrade Python on MacOS:
9.
Upgrade Python on Linux:
10.
What if Your Computer has Multiple Python Versions Installed?
11.
Python 2 vs Python 3
12.
Frequently Asked Questions
12.1.
Can we have 2 Python versions in Windows?
12.2.
Which Python version is best for Windows 10?
12.3.
How to upgrade the Python version in cmd?
12.4.
Which version of Python should I use?
13.
Conclusion
Last Updated: May 3, 2024
Easy

How to Check Python Version for Windows, Mac, and Linux

Author Tashmit
1 upvote

Introduction

Python is an influential and widespread programming language with many applications and a large community of developers. It is easy to learn and use, making it an ideal choice for beginners and experienced programmers. It is a high-level, interpreted programming language widely used for various applications, including Web Development, Data Analysis, Artificial Intelligence, Scientific Computing, and more. 

How to check python version in CMD

Check Python Version: Command-Line

In this article, we will focus on understanding how to check the Python-version in CMD on different systems. We will check the Python version in Windows, macOS, and Linux. So let’s get started.

i) Windows

The Python version in Windows operating systems can be checked using the command 'python --version. Windows generally do not have pre-installed Python in the system. Still, if you're not sure, you can check by following the below steps. 

First, open the command prompt in your windows system, and write the command:

python --version


The above command will show the version installed in your Windows system. 


If Python is not installed in your system, you can download it from here. After downloading and installing Python, you can run the above command in the command prompt and get to know the version installed in your system.

ii) MacOS

You can install the Python version from here for macOS. After successful installation, you can open the terminal and write the following command to know the Python version:

python --version


With this command, the terminal will show which version of Python is installed on your mac.

Practice this code with the help of Online Python Compiler

iii) Linux

The Linux systems generally come with Python already installed in them. But if your system does not have Python installed, you can install it from here.

After successfully installing Python, you can open the terminal and write the following command to check the python version:

python --version


The above command will display the Python version you installed in your Linux system.

Check Python Version: Script

You can use a script to check the Python version installed on a machine. By doing so, we may discover the precise version number and other details about the Python interpreter currently being utilised. The main, minor, and micro version numbers, the release level, and the serial number can all be retrieved by running the script.

i) Various information string: sys.version :

 The `sys.version` information string is a variable within Python's `sys` module, designed to furnish the version number and supplementary details pertaining to the installed Python interpreter. This string encompasses the version number, build particulars, and various additional information.

Script:

import sys

# Print the sys.version information string
print(sys.version)

 

Output:

output

ii) Tuple of version numbers: sys.version_info :

In Python's `sys` module, `sys.version_info` is a tuple consisting of individual integers that represent the version number of the Python interpreter. The tuple follows the format (major, minor, micro, releaselevel, serial). For instance, the tuple (3, 9, 2, 'final', 0) corresponds to Python version 3.9.2.

Script:

import sys

# Print the sys.version_info tuple
print(sys.version_info)

 

Output:

output

iii) Version number string: platform.python_version() :

The `platform.python_version()` function, part of the `platform` module, facilitates obtaining a concise representation of the Python interpreter's version number. It furnishes a streamlined version number devoid of supplementary details or build information. As an illustration, its output could manifest as '3.9.2'.

Script:

import platform

# Print the Python version number string
print(platform.python_version())

 

Output:

output

iv) Tuple of version number strings: platform.python_version_tuple() :

platform.python_version_tuple() is a function in the platform module that returns a tuple containing the version number of the Python interpreter as individual strings. The tuple has the same format as sys.version_info, but each element is a string instead of an integer. For example, ('3', '9', '2', 'final', '0').

Script:

import platform

# Print the Python version number tuple as strings
print(platform.python_version_tuple())

 

Output:

output

Also see, Swapcase in Python, and  Convert String to List Python
 

Check out this article - Quicksort Python.

Must Read Invalid Syntax in Python.

Check Python Version: Integrated Development Environments (IDE)

To check the Python version in integrated development environments (IDEs) like Visual Studio Code or PyCharm, open the integrated terminal and run the command python --version or python -V. The terminal will display the installed Python version.

i) Checking Python Versions in Visual Studio Code

  • Open Visual Studio Code: Launch Visual Studio Code if it's not already running.
     
  • Create or Open a Python File: You can create a new Python file or open an existing one by going to "File" > "Open File" or "File" > "New File" and saving it with a .py extension.
     
  • Open the Integrated Terminal: To check your Python version, you'll need to access the integrated terminal in Visual Studio Code. You can do this by going to "View" > "Integrated Terminal."
     
  • Run the Python Version Command: In the integrated terminal, type the following command and press Enter:
python --version

 

  • Check the Output: The output in the terminal will show the Python version.

ii) Checking the Python version in PyCharm

  • Open PyCharm: Launch PyCharm if it's not already running.
     
  • Create or Open a Python Project: You can create a new Python project or open an existing one.
     
  • Open the Terminal: To check your Python version, you'll need to access the terminal in PyCharm. You can do this by going to "View" > "Tool Windows" > "Terminal."
     
  • Run the Python Version Command: In the terminal, type the following command and press Enter:
python --version

 

  • Alternatively, you can use the following command to get more detailed version information:
python -V

 

  • Check the Output: The output in the terminal will show the Python version.
     

What are the Different Python Versions?

Python has gone through several major versions, each with its own improvements and features. These are the significant Python versions:

  • Python 1.0 (January 26, 1994): The initial release of Python, laying the foundation for the language.
     
  • Python 2.x Series (2000-2010): This series introduced many features and became widely adopted. Versions like Python 2.5, and 2.7 were popular.
     
  • Python 3.0 (December 3, 2008): A major overhaul with backward-incompatible changes to improve language consistency and remove redundancies.
     
  • Python 3.x Series (2008-Present): A series of releases with continued improvements. Python 3.9 was released in October 2020.
     
Python Versions  Release Date
Python 1.0 January 1994
Python 1.5 December 31, 1997
Python 1.6 September 5, 2000
Python 2.0 October 16, 2000
Python 2.1 April 17, 2001
Python 2.2 December 21, 2001
Python 2.3 July 29, 2003
Python 2.4 November 30, 2004
Python 2.5 September 19, 2006
Python 2.6 October 1, 2008
Python 2.7 July 3, 2010
Python 3.0 December 3, 2008
Python 3.1 June 27, 2009
Python 3.2 February 20, 2011
Python 3.3 September 29, 2012
Python 3.4 March 16, 2014
Python 3.5 September 13, 2015
Python 3.6 December 23, 2016
Python 3.7 June 27, 2018
Python 3.8 October 14, 2019

How to Update Python version to the latest version?

To update Python to the latest version, download the latest installer from the official Python website and run it, ensuring to add Python to your system's PATH during installation.

Upgrade Python on Windows:

  • Visit the Python Website: Go to the official Python website and download the latest Python installer for Windows.
     
  • Run the Installer: Run the downloaded installer. Make sure to check the box that says "Add Python X.X to PATH" during installation. This step ensures Python is added to your system's PATH environment variable.
     
  • Complete Installation: Follow the installation prompts, and Python will be upgraded to the latest version.
     
  • Verify Installation: Open Command Prompt and type python --version to verify that the new Python version is installed.

Upgrade Python on MacOS:

  • Open Terminal: Launch the Terminal app on your Mac.
     
  • Check Current Version: Verify your current Python version by running python --version or python3 --version.
     
  • Install Homebrew (if not already installed): If you don't have Homebrew, you can install it by following the instructions at https://brew.sh/.
     
  • Upgrade Python: Use Homebrew to upgrade Python by running the following commands:
brew upgrade python

Upgrade Python on Linux:

  • Open Terminal: Launch your terminal application.
     
  • Update Package List: Update your package list to ensure you're getting the latest version of Python:
sudo apt update

 

  • Upgrade Python: Upgrade Python using the following command:
sudo apt install python3 --reinstall

What if Your Computer has Multiple Python Versions Installed?

Having multiple Python versions installed on your computer allows you to work with different versions of Python for compatibility with various projects or applications. However, it can lead to challenges in managing dependencies and ensuring that the correct version is used for each project.

To address this, you can utilize virtual environments, such as venv or virtualenv, which enable you to create isolated environments for each project with its own Python version and dependencies. This ensures that each project runs with the appropriate Python version without interfering with others.

Additionally, tools like pyenv allow you to manage multiple Python versions globally on your system, making it easier to switch between versions as needed.

Python 2 vs Python 3

Here’s a table differentiating Python2 and Python3 on various factors: 

  Python 2 Python 3
Print Statement Uses print as a statement Uses print() as a function
Division Integer division by default (5/2 = 2) Float division by default (5/2 = 2.5)
Unicode Handling Uses ASCII as default encoding Uses Unicode (UTF-8) as default encoding
Syntax Allows both parentheses and no parentheses for print Requires parentheses for print
String Handling Uses ASCII strings by default Uses Unicode strings by default
Exception Handling Uses the except ExceptionType, e syntax Uses the except ExceptionType as e syntax
Iteration Uses xrange() for efficient looping Uses range() for looping
Libraries Many libraries are only compatible with Python 2 Libraries are being updated to support Python 3

Frequently Asked Questions

Can we have 2 Python versions in Windows?

Yes, you can have multiple Python versions on Windows by installing them in separate directories. Make sure to specify the desired version when running Python commands.

Which Python version is best for Windows 10?

For Windows 10, it's recommended to use the latest stable release of Python, which is currently Python 3.x. As of now, Python 3.10 is the latest stable version, offering improved performance, security updates, and new features compared to earlier versions.

How to upgrade the Python version in cmd?

To update the Python version on the command prompt or CMD, use the pip package manager. In order to upgrade to the most recent version of Python, open CMD and type "pip install --upgrade python".

Which version of Python should I use?

You should use the latest stable release of Python, which is Python 3.x. As of now, Python 3.10 is the latest stable version, offering improved performance, security updates, and new features compared to earlier versions.

Conclusion

In this article, we have learned how to check Python version in CMD in Windows, macOS, and Linux operating systems. You can visit the official website of Python to download it.

Recommended Reading:

pwd command in linux

You can also consider our paid courses such as DSA in Python to give your career an edge over others!

Live masterclass