You are currently viewing How to check Python Version?

How to check Python Version? There are multiple ways you can check the installed version of python. Python comes in different versions and it is essential to know the version of Python installed on your system before starting to work with it. In this article, We will learn the possible ways to find the installed version of python.

Advertisements

1. Check Python Version from Command Prompt ( CMD)

To check the version of Python installed on your Windows computer, you can use the Command Prompt (CMD) and run a simple command python --version.

To check the Python version from the command prompt (CMD), follow the below steps.

  1. Open the Command Prompt on your Windows computer.
  2. Type cmd in the Windows search bar and select “Command Prompt” from the results.
  3. Once the Command Prompt is open, type python --version
  4. It will display the version of python.

# Check Python version
C:\>python --version
Python 3.11.2 # Prints on console
check version of python

You can also use python -V that will yield the same output.


# Check Python version
C:\>python -V
Python 3.11.2 # Prints on console

2. Check Python Version from Shell

This method is pretty much the same as using a command prompt, however, in this method, we will be using Shell instead of the command prompt to check the version of Python installed.

To check the version of Python installed on your system from the shell, follow these steps.

  1. Open the shell on your system.
  2. Now type python --version command and press Enter
  3. In the next line you will see the version of python installed.
find version python installed

3. Programmatically Check Python Version

If you need to check the version of python inside your program. Then python also provides several ways to programmatically check the version of Python installed on your system.

3.1 Using platform Module

The first method is to use the platform module. It is an easy way to programmatically check the version of Python installed on your system. You can use the python_version() function from the platform module to get the version of Python.


# Programmatcially Check the version of Python
import platform
python_versoin = platform.python_version()
print(python_versoin)

# Output
# 3.11.2

3.2 Using distutils Module

You can also use the distutils module in Python to get the version of Python installed on your system. The distutils module is a part of the standard library and is used for packaging and distribution of Python modules.


# Programmatcially Check the version of Python
from distutils.sysconfig import get_python_version
print(get_python_version())

# Output:
# 3.11

4. Check if You have two Version of Python

It is possible to have multiple versions of Python installed on your system. This can happen when you install a new version of Python without uninstalling the previous version. See the below steps:

  1. Open the Command Prompt or shell on your system.
  2. Type where python command and press Enter
  3. This command will display the path of all the Python version.
  4. If you have two versions of Python installed, you will see two different paths in the output.
Two versions of python installed on the comptuter

The command to check if you have installed multiple version of python is :


# Command to Check All versions of Python Installed
C:\>where python

5. Why it is Important to Check Python Version

There can be tons of different purposes to find the version of python installed. Some of them are below:

  1. Checking the version can help you avoid compatibility issues and ensure that your code works as expected.
  2. Checking the version can help you determine if you need to update to a newer version for security reasons.
  3. Newer versions of Python often include performance improvements and optimizations.
  4. It can help you ensure that you have the correct version for your dependencies.

6. What are the Major Versions of Python

Just like any other programming language. Python is constantly updating. The first version of python was released in the early 1990s. See the following are the most popular versions of python:

6.1 Python 1.x

The first stable version of Python was released in 1994. This version of Python introduced many of the features that are still used in Python today, such as the module system, exception handling, and the basic data types.

6.2 Python 2.x

The second major version of Python, Python 2.x, was released in 2000. This version of Python introduced many new features, such as list comprehension and support for Unicode. Python 2.x also introduced a number of backward-incompatible changes, which meant that some code written for Python 1.x would not work in Python 2.x.

6.3 Python 3.x

Python 3.x is the latest major version of Python and was released in 2008. This version of Python introduced many new features and improvements, such as improved Unicode support, the better syntax for handling exceptions, and a more consistent library API. Python 3.x also introduced many backward-incompatible changes, which meant that some code written for Python 2.x would not work in Python 3.x.

7. Summary and Conclusion

In this article, we have learned how to check the version of python. As we have discussed python can have multiple versions and it is important to know the version of python that you have to work with. I hope this article was helpful. If you have any questions please leave them in the comment section.

Happy Coding!