How to Check Python Version – A Quick Guide

1. Check Python Version from the Command Line

Python provides a built-in command to check its version.

βœ… Step 1: Open the Command Line

  • Windows: Press Win + R, type cmd, and press Enter.
  • macOS/Linux: Open the Terminal (Ctrl + Alt + T on Linux).

βœ… Step 2: Run the Python Version Command

For Python 3 (recommended)

python3 --version

or

python3 -V

For Python 2 (if installed)

python --version

πŸŽ‰ Example Output:

Python 3.10.12

πŸ’‘ Best Practice: Use python3 --version to ensure you’re checking Python 3, as some systems may default to Python 2.

2. Check Python Version Inside a Script

You can also check the Python version inside a script using the sys module.

βœ… Step 1: Create a Python Script (check_version.py)

Β 
import sys

print("Python Version:", sys.version)
print("Version Info:", sys.version_info)

βœ… Step 2: Run the Script

python check_version.py

πŸŽ‰ Example Output:

Python Version: 3.10.12 (main, Dec 25 2023, 10:05:17) [GCC 9.4.0]
Version Info: sys.version_info(major=3, minor=10, micro=12, releaselevel='final', serial=0)

πŸ’‘ Best Practice: Use sys.version_info for detailed version checks in scripts.

3. Check Python Version in VS Code & PyCharm

βœ… VS Code

  1. Open the Terminal (Ctrl + ~).
  2. Run
python --version

orΒ  python3 –version

βœ… PyCharm

  1. Open PyCharm and go to File > Settings > Project: YourProject > Python Interpreter.
  2. The Python version will be displayed next to the selected interpreter.

πŸ’‘ Best Practice: In VS Code, use the Python: Select Interpreter command to check and change the Python version.