How to Check Python Version in Linux, Windows, and macOS

Updated on July 24, 2024

Article Outline

Python is a high-level and dynamic language. It sees frequent new releases every year — each time bringing improved functionality and bug fixes— from its development organisation. Web development, data analysis, machine learning, and scripting are just a few examples of what tasks can be achieved using the Python programming language. However, it should be noted that Python, like any other software program, exists in multiple versions. Regulatory oversight on which version your machine runs is thus a task to ensure conformity with the scripts to be run.

 

In this article, we will go through in detail on how to check the Python version in Linux, Windows, and macOS. We will use different methods to check for the installed Python version in our system along with the major and key versions Python has released till now.

What is Python?

Python stands as a high-level programming language — not to mention a powerful one — that offers effective high-level data structures and an uncomplicated introduction to the object-oriented paradigm. While Python is recognized for its easy-to-understand syntax, it also excels in the world of object-oriented programming effectiveness and dynamic typing. Python makes use of an interpreter, alongside a wide range of standard libraries, which allows for program development. As such, it positions itself as an ideal scripting language— finding applicability in rapid application development across different domains.  Since its first release in 2001 i.e., Python 2.0.1 version, it has come up to its latest Python 3.12.4 version with various of the latest features in its effectiveness, security, and bug fixes.

*Image
Get curriculum highlights, career paths, industry insights and accelerate your technology journey.
Download brochure

What is the Python version?

Python versions are the new releases that are released by the organisation with new features, bug fixes, security updates, and many more things. Since its introduction, Python has seen multiple major revisions, the most notable being Python 2 and Python 3. While Python 2 became inactive on January 1, 2020, Python 3 is the most recent major version and is still actively maintained. Knowing the version of Python you are using is crucial because every version of the language adds new enhancements, features, and occasionally unsettling changes.

Checking Python Version in Linux

Linux is a popular operating system to run Python programs and develop applications using Python. Linux offers the best command line and shell scripting features for Python. To check the Python version in Linux, we have different methods to do it including:

 

  • Using shell
  • Using command line
  • Using Python Script
  • Using Virtual environments

Using Shell

Linux provides an interactive shell for the users to use its various functionalities. Checking the Python version using this interactive shell is very easy. To check the Python version, follow the below steps:

 

1. Open your terminal and run the following command:

For Python 2.x:

python

For Python 3.x:

python3

 

2. Once you’re in an interactive shell, check for the version of Python by running the below commands:

 

import sys

print(sys.version)

Using the Command Line

Using the Linux command line or terminal, you can also check the Python version. To check the Python version, follow the below steps:

 

  1. Open your terminal (use Ctrl + alt + t) and run the following command:

For Python 2.x:

python –version

 

Or

 

python -V

For Python 3.x:

python3 –version

 

Or

 

python3 -V

Using Python Script

Python is popular for its scripting features. To check for the Python version, we can write a script also. See the below steps:

 

1. Create a new file with any name like check_ver.py and add the following code to it:

import sys print("Your installed Python version is: ") print(sys.version) print("Your installed Python information is: ") print(sys.version_info)

2. Run the script:

<strong>For Python 2.x:</strong> python check_ver.py For Python 3.x: python3 check_ver.py

Using Virtual Environments

We can also create Python virtual environments to check for the versions. To do this, create a virtual environment by activating it, and you may use the version command to see the Python version there. Let’s see how:

 

1. Create a Virtual Environment

 

For Python 3.x:

python3 -m venv myenv

 

 2. Activate the Virtual Environment

 

For bash or zsh:

source myenv/bin/activate

 

For the fish shell:

source myenv/bin/activate.fish

 

3. Check the Python version by running the command

 

python –version

 

Or

 

python -V

Checking Python Version in Windows

Windows OS is also used to run Python programs and develop the latest applications. Tasks like Machine learning, artificial intelligence, and data analysis are performed in Windows using Python. Therefore, it is necessary to be updated with the latest version of Python. To check the Python version in Windows, we have different methods to do it including:

 

  • Using PowerShell
  • Using command line
  • Using Python Script
  • Using Virtual environments

Using PowerShell

Windows provides the PowerShell same as the shell in Linux, for the users to use its various system administration functionalities. Checking the Python version using this PowerShell is easy. To check the Python version, follow the below steps:

 

1. Open the PowerShell (use Win + X) and select Windows PowerShell or Windows PowerShell (Admin)

 

2. Run the following command:

For Python 2.x:

python –version

For Python 3.x:

python3 –version

Using the Command Line

Using the Windows terminal or command line, you can also check the Python version. To check the Python version, follow the below steps:

 

  1. Open your terminal (use Win + R), type “cmd”, and press ENTER. Run the following command:

 

For Python 2.x:

python –version

 

Or

 

python -V

For Python 3.x:

python3 –version

 

Or

 

python3 -V

Using Python Script

Python is popular for its scripting features. To check for the Python version, we can write a script in Windows also. See the below steps:

 

1. Create a new file with any name like check_ver.py and add the following code to it:

import sys print("Your installed Python version is: ") print(sys.version) print("Your installed Python information is: ") print(sys.version_info)

2. Run the script:

<strong>For Python 2.x:</strong> python check_ver.py For Python 3.x: python3 check_ver.py

Using Virtual Environments

We can also create Python virtual environments in Windows to check for the versions. To do this, create a virtual environment by activating it and using the version command to see the Python version there. Let’s see how:

 

1. Create a Virtual Environment

 

For Python 3.x:

python -m venv myenv

 

2. Activate the Virtual Environment

 

For cmd:

myenvScriptsactivate

 

For powershell:

myenvScriptsActivate.ps1

 

3. Check the Python version by running the command

 

python –version

 

Or

 

python -V

Checking Python Version in macOS

MacOS is known for its performance in various development tasks. To check the Python version in Windows, we have different methods to do it including:

 

  • Using Mac Terminal
  • Using Python Script
  • Using Virtual environments

Using the Mac Terminal

Using the macOS terminal, you can also check the Python version. To check the Python version, follow the below steps:

 

  1. Open your terminal (use Cmd + space), type “terminal”, and press ENTER.
  2. Run the following command:
<strong>For Python 2.x:</strong> python –version For Python 3.x: python3 –version

Using Python Script

Python is popular for its scripting features. To check for the Python version, we can also write a script in Mac. See the below steps:

 

1. Create a new file with any name like check_ver.py and add the following code to it:

import sys print("Your installed Python version is: ") print(sys.version) print("Your installed Python information is: ") print(sys.version_info)

2. Run the script:

<strong>For Python 2.x:</strong> python check_ver.py For Python 3.x: python3 check_ver.py

Using Virtual Environments

We can also create Python virtual environments in Mac to check for the versions installed. To do this, create a virtual environment by activating it and using the version command to see the Python version there. Let’s see how:

 

1. Create a Virtual Environment

 

For Python 3.x:

python -m venv myenv

 

2. Activate the Virtual Environment

 

source myenv/bin/activate

 

3. Check the Python version by running the command

 

python –version

Why Checking the Python Version is Important?

To get updated with the latest features, security updates, etc., it becomes important to check the Python version of your system. Having checked the Python version installed on your system can ensure that your application is free from the previous bug fixes, security fixes, etc. Here are some of the factors that significantly imply why it’s important to check the Python version:

 

  • Compatibility– Compatibility is a major reason why it’s important to check the latest version of Python as some frameworks and libraries might only function with particular versions.
  • Debugging– Having a working knowledge of the Python version facilitates efficient troubleshooting and debugging.
  • Documentation– Referencing the appropriate documentation is ensured when you are aware of your version, as different versions have different documentation.
  • Virtual Environments– To maintain consistency between development and production environments, managing virtual environments frequently necessitates knowing the Python version.

What are the Different Python Versions?

Python’s first version was launched in 1991, and since then, it has undergone various changes, including some minor and others major, with a slew of new features or security enhancements and, at times, even adjustments that would change the game. Developers need to have a good grasp of the different versions of Python if they are to ensure compatibility while also staying alongside the latest developments in the language. Here’s a preview of some significant changes made to Python’s version:

Major Python Versions

  • Python 1.0- This was the very first version that laid the foundation for Python’s development.
  • Python 2.x- The 2.x versions were introduced in 2000, with many new major changes like list comprehensions, cycle-detecting garbage collection, and Unicode support. However, Python 2.7 reached its end of life in January 2020.
  • Python 3.x- This was released in December 2008, Python 3.x introduced many changes that are not backward-compatible with Python 2.x, such as print function, integer division, and the reorganisation of standard libraries. Python 3 also came up with the 2to3 utility for auto-translation of Python 2 to Python 3. Python 3 is the current and actively maintained version of the language.

Key Python Versions

Below are the key Python versions starting from its pre-release and first launch till the current versions:

 

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
Python 3.9 October 5, 2020
Python 3.10 October 4, 2021
Python 3.11 October 24, 2022
Python 3.12 October 02, 2023
Python 3.13 October 10, 2024 (planned)

How to Update the Python version to the latest version?

Upgrading to the latest version in Python ensures that all new features and bug fixes are being supported in your project. To update the Python version, some steps need to be performed in different operating systems. We will see all the steps for updating the Python version to the latest version in Linux, Windows, and macOS:

For Linux:

Steps to update the Python version to the latest version in Linux:

 

1. Using Python package manager

 

For (Debian OS)

 

Open terminal: Start your terminal and run the following command.

 

Update the package:

sudo apt update

sudo apt install python3 –reinstall

 

For (Fedora OS)

 

Open terminal: Start your terminal and run the following command.

 

Update the package:

sudo dnf install python3 –reinstall

 

2. Manual Download

 

The simplest way to upgrade is to download the latest version from Python’s official website.

Extract the file:

tar -xvzf Python-3.8.0.tgz  # Replace with your desired version

 

Navigate to the extracted directory:

cd Python-3.8.0

 

Build and install:

./configure

make

sudo make install

 

3. Using deadsnakes

 

If you’re using Ubuntu, there’s an additional PPA, known as deadsnakes, that can be used to update to Python’s latest version. Here’s how you can update:

sudo add-apt-repository ppa:deadsnakes/ppa

sudo apt update

sudo apt install python3.8  # Replace with your desired version

For Windows:

Steps to update the Python version to the latest version in Windows:

 

  1. First, download the latest version from Python’s official website.
  2. Open the file and run the installer to install Python’s latest version.
  3. While installing make sure to check the box: “Add Python to PATH” to ensure the environment variables are added to your system.
  4. Continue following the steps.

For macOS:

Steps to update the Python version to the latest version in macOS:

 

Method 1: Using Manual Download Installer

 

  1. Download the latest version of macOS Python’s version from Python’s official website.
  2. Run the installer to install the version.
  3. Follow the next steps.

 

Method 2: Using Homebrew

 

  1. First, download and install Homebrew, a powerful package manager for Mac OS.
  2. Open your terminal: Press command+space and type “terminal”.
  3. Run the command:
    /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
  4. Your terminal may ask you for Super User-level access. So just type in your regular Mac login password to continue. Next press enter.
  5. Update Homebrew and install Python:

brew update

brew install python

How to Downgrade the Python version?

There are situations where you need to downgrade your Python version to a specific version that is compatible with the application or project you’re working on. Here are the steps for downgrading your Python version in Linux, Windows, and macOS:

For Linux:

Steps to downgrade the Python version to the specific version in Linux:

 

Method 1: Using deadsnakes

 

1. Open your terminal and run the command:

sudo add-apt-repository ppa:deadsnakes/ppa sudo apt update sudo apt install python3.7  # Replace with the desired version

2. Wait for the installation to complete

 

Method 2: Using pyenv

 

1. Download and install the Python’ package “pyenv”. Run the following command:curl https://pyenv.run | bash

 

2. Now, add “pyenv” to your shell configuration file:

export PATH="$HOME/.pyenv/bin:$PATH" eval "$(pyenv init --path)" eval "$(pyenv init -)" eval "$(pyenv virtualenv-init -)"

3. Downgrade to specific Python version:

 

pyenv install 3.5.4  # Replace with your desired version

pyenv global 3.5.4

 

For Windows:

Steps to downgrade the Python version to the specific version in Windows:

 

  1. Uninstall the current version
    Go to the control panel. Find the Python installer and uninstall it.
  2. Install the specific version
    Download the specific version from Python’s official website.
  3. Run the installer and install the specific version.
  4. Use chocolatey
    Run the following command to install a specific version using Chocolatey:

choco install python –version=3.7.9  # Replace with the desired version

For macOS:

Steps to downgrade the Python version to the specific version in macOS:

 

1. Uninstall the current version
Use the homebrew, and run the command:brew uninstall python

 

2. Install the specific version

Download the specific version from Python’s official website.

 

3. Run the installer and install the specific version.

 

4. Use pyenv
Run the following command to install pyenv:

brew install pyenv

 

5. Now, add “pyenv” to your shell configuration file:

export PATH="$HOME/.pyenv/bin:$PATH" eval "$(pyenv init --path)" eval "$(pyenv init -)" eval "$(pyenv virtualenv-init -)"

6. Downgrade to specific Python version:

 

pyenv install 3.5.3 # Replace with your desired version

pyenv global 3.5.3

Conclusion

For developers, ensuring the Python version is up to date is crucial. This is because it equips them with the most recent features, bug fixes, and security updates, which in turn facilitate the development of applications and programs. We have discussed in detail the different methods to verify the Python version on Windows, Linux, and macOS in this article; take note so you can identify and take charge of your Python environment accurately. Knowing your Python version- whether you work through the terminal, scripts, or virtual environments— plays a major role in guaranteeing compatibility as well as streamlining your development process.

FAQs
Yes, you can have multiple versions of Python in Windows. To install multiple versions, you can install them in different directories so that there is no crash between multiple versions of Python.
Open the Mac terminal, type: python --version, and press return. Now, If Python is installed, you will see a message telling you the version name.
Use the Start Menu to see if Python is installed on your Windows computer. To do so, perform the following: To access the Start Menu, either click the Start button or press the Windows key. Put "python" in the search bar. Python should appear as the best match if it is installed.
You may be sure you have access to the newest features, speed boosts, and security patches by updating to the most recent version of Python. Python updates frequently include improvements that make writing code more secure and effective.
Yes, you can install and run Python in Linux and perform all tasks of Python including writing scripts, running programs, development applications, machine learning, data science, and many more things. Linux offers you the best security features for your system and that can be used for your Python development environment too.

Updated on July 24, 2024

Link
left dot patternright dot pattern

Programs tailored for your success

Popular

IIT Courses

Management

Data Science

Finance

Technology

Future Tech

Upskill with expert articles

View all
Hero Vired logo
Hero Vired is a leading LearnTech company dedicated to offering cutting-edge programs in collaboration with top-tier global institutions. As part of the esteemed Hero Group, we are committed to revolutionizing the skill development landscape in India. Our programs, delivered by industry experts, are designed to empower professionals and students with the skills they need to thrive in today’s competitive job market.
Blogs
Reviews
Events
In the News
About Us
Contact us
Learning Hub
18003093939     ·     hello@herovired.com     ·    Whatsapp
Privacy policy and Terms of use

|

Sitemap

© 2024 Hero Vired. All rights reserved