2 ways to check Python version:
- Using the command line
- Using a Python Script
Method 1: Using the command line
Check Version in Linux
If you’re using Linux, open your command line interface and type the following command:
python --version
or
python3 --version
The output will show the installed version.
Check Version in Windows
In a Windows environment, open the Command Prompt (CMD) and type the following command:
python --version
If Python is already installed on your system, it will display the installed version.
If the Python –version does not work in Linux or Windows, you can also write one of the following commands.
- python -V
- python -VV
Installing Python, updating it, installing packages and third-party software like Anaconda, and installing and updating pip are some of the most frequently used operations users perform in their system.
Check Version in MacOS
To check the Python version on a Mac, you can open your terminal and use the python –version command and then press Enter.
python --version
or
python3 --version
Method 2: Using a Python Script
You can import the sys module and use the sys.version attribute, which returns the installed version on your system.
import sys
print(sys.version)
Output
3.11.7 (main, Dec 4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)]