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:

`javascript

python -V

`

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

`javascript

Python 3.10.4

`

If the command doesn’t work, try:</code></pre>javascript

python3 --version

<pre data-language=""><code class="language-">Or:</code></pre>javascript

py --version

<pre data-language=""><code class="language-">## Checking Python Version on macOS

For macOS users:

1. Open Terminal (press

Cmd + Space, type Terminal, and hit Enter).

2. Run:

`javascript

python3 --version

`

Since macOS often comes with Python 2 pre-installed, using

python might show an outdated version.

To verify all installed versions, use:</code></pre>javascript

ls /usr/bin/python*

<pre data-language=""><code class="language-">## Checking Python Version on Linux

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

1. Open Terminal.

2. Type:

`javascript

python3 --version

`

Or:

`javascript

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</code></pre>javascript

import sys

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

<pre data-language=""><code class="language-">### Using platform Module</code></pre>javascript

import platform

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

``