'Coding has over 700 languages', '67% of programming jobs aren’t in the technology industry', 'Coding is behind almost everything that is powered by electricity'
Last Updated: Dec 26, 2023
Easy

How to check python version for Windows, Mac and Linux

Author Tashmit
1 upvote
gp-icon
Basics of python
Free guided path
7 chapters
99+ problems
gp-badge
Earn badges and level up

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.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

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.0January 1994
Python 1.5December 31, 1997
Python 1.6September 5, 2000
Python 2.0October 16, 2000
Python 2.1April 17, 2001
Python 2.2December 21, 2001
Python 2.3July 29, 2003
Python 2.4November 30, 2004
Python 2.5September 19, 2006
Python 2.6October 1, 2008
Python 2.7July 3, 2010
Python 3.0December 3, 2008
Python 3.1June 27, 2009
Python 3.2February 20, 2011
Python 3.3September 29, 2012
Python 3.4March 16, 2014
Python 3.5September 13, 2015
Python 3.6December 23, 2016
Python 3.7June 27, 2018
Python 3.8October 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

 

Python 2 vs Python 3

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

 Python 2Python 3
Print StatementUses print as a statementUses print() as a function
DivisionInteger division by default (5/2 = 2)Float division by default (5/2 = 2.5)
Unicode HandlingUses ASCII as default encodingUses Unicode (UTF-8) as default encoding
SyntaxAllows both parentheses and no parentheses for printRequires parentheses for print
String HandlingUses ASCII strings by defaultUses Unicode strings by default
Exception HandlingUses the except ExceptionType, e syntaxUses the except ExceptionType as e syntax
IterationUses xrange() for efficient loopingUses range() for looping
LibrariesMany libraries are only compatible with Python 2Libraries are being updated to support Python 3

Frequently Asked Questions

Q. 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.

Q. How to run Python from cmd?

Open cmd, and navigate to the desired directory using the "cd" command. Then type "python" followed by the name of your script.py file.

Q. 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".

Q. Which version of Python should I use?

In the Python 2 vs. Python 3 debate, Python 3 emerges as the best choice for learning in 2023, though Python 2 remains relevant in certain cases.

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!

Happy learning, Ninja!

Previous article
What is Encapsulation in Python?
Next article
iloc() Function in Python
Guided path
Free
gridgp-icon
Basics of python
7 chapters
127+ Problems
gp-badge
Earn badges and level up
Live masterclass