How to check Python Version : Windows, Linux and Mac
Python has multiple versions, and it's important to know which version is installed on your system. This information is crucial because different Python versions may have variations in syntax or libraries, and ensuring you're using the correct version is vital for compatibility with your projects. In this guide, we'll explore various straightforward methods on how to check the Python version on your Linux, Windows, and Mac systems.
How to Check Python Version on Windows and Mac
To check the Python version on Windows or Mac system, we can follow these methods:
- Using the Command Prompt/Terminal
- Checking in the Interactive Shell
Using the Command Prompt/Terminal
Open the Command Prompt for Windows by searching for "cmd" in the Windows Start menu or open Terminal for Mac by searching Terminal in the MacOS spotlight search. Then, use one of the following commands:
For Python 2:
python --version
or
python -V
For Python 3:
python3 --version
or
python3 -V

Using Interactive Shell
We can also find the Python version in the interactive shell. Open the Command Prompt/terminal and enter one of the following commands:
For Python 2:
python
For Python 3:
python3
Once you are in the Python interactive shell, you can check the version with these Python commands:
import sys
print(sys.version)

How to Check Python Version on Linux
We can use the following methods to check the Python version on Linux systems like Ubuntu, Debian, Arch, etc. These methods can be used to find Python version:
- Using the Command Line
- Checking in the Interactive Shell
- Using Package Managers
- Checking the Path
Check the Python Version Using the Command Line
The command line provides a straightforward way to get the Python version. Open your terminal and use this simple check Python version command:
For Python 2:
python --version
or
python -V
For Python 3:
python3 --version
or
python -V

NOTE: These commands will display the Python version installed on your Linux system.
Check Python Version Using Interactive Shell
Python's interactive shell is another way to find Python version. Open your terminal and enter one of the following commands:
For Python 2:
python
For Python 3:
python3
Once you are in the Python interactive shell, you can get Python version with the following Python commands:
import sys
print(sys.version)

Check Python Version Using Package Managers
If you installed Python using a package manager, you can use these tools to check the Python version.
For Debian-based systems, such as Ubuntu, you can use `apt`:
apt show python3

For Red Hat-based systems, like CentOS, you can use yum:
yum info python3
NOTE: These commands will provide detailed information about the Python version installed on your system.
Finding Python Version by Checking the Path
We can also determine the path to the Python interpreter and indirectly obtain information about the installed version using the `which` command:
which python3
This command will return the path to the Python interpreter. We can then use this path to check the version:
/path/to/python --version
Replace '/path/to/python' with the actual path obtained from the previous which command.

Also Read: