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.
1. Check Python Version from Command Prompt ( CMD)
To check the version of Python installed on your Windows computer using the Command Prompt (CMD), you can use a simple command.
To Check the Python version from the Command Prompt (CMD) follow these steps:
Open the Command Prompt on your Windows computer.
Type cmd in the Windows search bar and select “Command Prompt” from the results.
Once the Command Prompt is open, type python –version
It will display the version of python.
C:>python –version
Python 3.11.2
You can also use python -V that will yields the same output:
C:>python -V
Python 3.11.2
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 on your system.
To check the version of Python installed on your system from the shell, follow these steps:
Open the shell on your system.
Now type python –version command and press Enter
In the next line you will see the version of 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:
Open the Command Prompt or shell on your system.
Type where python command and press Enter
This command will display the path of all the Python version.
If you have two versions of Python installed, you will see two different paths in the output.
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:
Checking the version can help you avoid compatibility issues and ensure that your code works as expected.
Checking the version can help you determine if you need to update to a newer version for security reasons.
Newer versions of Python often include performance improvements and optimizations.
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 comprehensions and support for Unicode. Python 2.x also introduced a number of backwards-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, better syntax for handling exceptions, and a more consistent library API. Python 3.x also introduced many backwards-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 have multiple version 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!
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 Read More Python, Python Tutorial