How to check Python Version : Windows, Linux and Mac
Python is a versatile and widely used programming language, and it is used for various tasks, from scripting to web development. Python, like many software, has different 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, giving you the confidence that you’re working with the right Python interpreter for your specific needs.
Check the Python Version on Linux
Linux is a popular platform for Python development and system administration. 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 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
Check Python Version Using the Command Line
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)
Checking Python Version in the Interactive Shell
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
Check Python Version Using Package Managers
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
You 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. You 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.
Finding Python Version by Checking the Path
Check Python Version on Windows and Mac
Python is widely used on Windows and Mac for application development, data analysis, and more. To check the Python version on Windows or Mac system, you can follow these methods:
- Using the Command Prompt/Terminal
- Checking in the Interactive Shell
Finding the Python Version 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
These commands will display the Python version installed on your Windows/ Mac system.
Check the Python Version Using Interactive Shell
You 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
the
python3
Once you are in the Python interactive shell, you can check the version with these Python commands:
import sys
print(sys.version)
This will display detailed information about your Python version.
Also Read:
Conclusion
In this article, we discussed how to check the Python version on Linux, Windows, and macOS (Mac). Knowing your Python version is crucial for compatibility with your projects, as different versions may have variations in syntax and libraries.Â
By following the provided methods, you can confidently determine the Python version on your system, ensuring you’re using the right interpreter for your specific needs on your chosen platform. Whether you’re a developer, system administrator, or Python enthusiast, understanding your Python version is fundamental to your work.
Last Updated :
05 Jan, 2024
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...