πHow to Check Python Version
πIntroduction
How to Check Python Version: Checking your Python version is essential for ensuring compatibility with libraries and frameworks. Whether you are a beginner or an experienced developer, this guide will help you verify your Python version across different operating systems such as Windows, Mac, and Linux.
πHow to Check Python Version Using Commands
Here are some quick commands to check your Python version in various environments:
πCommand Line Commands
How to Check Python Version
Command | Platform | Output Example |
python –version | Windows/Mac/Linux | Python 3.10.7 |
python3 –version | Windows/Mac/Linux | Python 3.10.7 |
python -v | Windows/Mac/Linux | Detailed version information |
python -VV | Linux | Full version details |
πHow to Check Python Version Using Python Script
Python scripts can also determine the Python version installed on your system. Use these sample codes:
πUsing sys Module
import sys
print(sys.version)
Output: 3.10.7 (tags/v3.10.7:6cc6b13, Sep 5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)]
πUsing platform Module
import platform
print(platform.python_version())
Output: 3.10.7
πUsing python_version()
from platform import python_version
print(“Current Python Version -“, python_version())
Output: Current Python Version – 3.8.10
πHow to Check Python Version on Windows
πSteps to Check Python Version in Command Prompt
- Open Command Prompt by typing cmd in the Windows search bar.
- Type the following command:
python –version
Output: Python 3.10.7
πSteps to Check Python Version in PowerShell
- Open PowerShell by typing “PowerShell” in the Start menu.
- Run the following command:
python3 –version
Output: Python 3.10.7
πHow to Check Python Version on Mac
πSteps to Check Python Version in Mac Terminal
- Open the Terminal by typing “Terminal” in the search box.
- Type the following command:
python3 –version
Output: Python 3.3.1
Alternatively, to check Python 2, use:
python –version
Output: Python 2.7.4
πHow to Check Python Version on Linux
πSteps to Check Python Version in Linux Terminal
- Open the Terminal.
- Type the following command:
python3 –version
Output: Python 3.5.2
To check Python 2 version:
python –version
Output: Python 2.7.12
πChecking Multiple Python Versions Installed
If multiple Python versions are installed, you can differentiate them as follows:
- To Check Python 2: python –version
- To Check Python 3: python3 –version
πKey Differences Between Python 2 and Python 3
- Python 3 uses Unicode for string storage by default, whereas Python 2 requires adding a u before string literals.
- Python 2 is no longer maintained; therefore, Python 3 is recommended for modern development.