
👉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.