common.loading

How to Check Python Version on Windows, macOS, and Linux

0
How to Check Python Version on Windows, macOS, and Linux
Helpful
0
Not Helpful

Python is a popular programming language used for everything from web development to data science. But sometimes, you need to find Python version installed on your system. Different versions bring new features, bug fixes, and security updates, making it essential to check Python version before running your projects. Knowing your Python version ensures compatibility with libraries and frameworks. Some applications require specific versions, and using the wrong one can cause errors.

This guide will show you how to check Python version on Windows, macOS, and Linux using simple commands. Whether you need to check which version of Python is installed, get Python version in a script, or find the right Python version command, we’ve got you covered.

Checking Python Version on Windows

If you're using Windows, follow these steps:

  1. Open the Command Prompt (Press Win + R, type cmd, and hit Enter).

  2. Type the following command and press Enter:

    python --version

    Or use:

    python -V
  3. If Python is installed, you’ll see output like this:

    Python 3.10.4

If the command doesn’t work, try:

python3 --version

Or:

py --version

Checking Python Version on macOS

For macOS users:

  1. Open Terminal (press Cmd + Space, type Terminal, and hit Enter).

  2. Run:

    python3 --version

    Since macOS often comes with Python 2 pre-installed, using python might show an outdated version.

To verify all installed versions, use:

ls /usr/bin/python*

Checking Python Version on Linux

Most Linux distributions come with Python pre-installed. To check:

  1. Open Terminal.

  2. Type:

    python3 --version

    Or:

    python -V

On some systems, python may refer to Python 2, while python3 points to Python 3.

Python Version Commands

CommandDescription
python --versionDisplays Python version (Windows/Linux)
python3 --versionChecks Python 3 version (macOS/Linux)
py --versionWorks on Windows to show the version

How to Check Python Version in a Script

Sometimes, you need to check Python version inside a script. These methods are useful when debugging or ensuring compatibility in your code. Here are some ways:

Using sys Module

import sys print("Python version:", sys.version)

Using platform Module

import platform print("Python version:", platform.python_version())

Share