Skip to main content

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

Learn how to check your Python version in the terminal, scripts, and virtual environments. Understand common issues and best practices for Windows, macOS, and Linux.
Jan 28, 2026  · 6 min read

Knowing which Python version you’re using is more important than it might seem. Many libraries and frameworks depend on specific Python versions, and code can behave differently across releases. Running scripts on an unsupported or unexpected version often leads to installation failures or runtime errors that are difficult to diagnose.

In this guide, I will walk you through simple, reliable ways to check your Python version across common operating systems, environments, and setups. If you are getting started in Python, I recommend taking our Introduction to Python course, which covers skills like data types, lists, basic functions, and packages.

How to Check Python Version from the Command Line

The most common way to check your Python version is by using your computer's terminal (Mac/Linux) or Command Prompt/PowerShell (Windows).

Using python --version

This command asks the system which Python interpreter is associated with the python command and prints its version.

python --version

This command works on most systems if python is properly configured in your PATH. However, the command might fail if python points to Python 2 or does not exist in the PATH.

Using python3 --version

Some systems, especially macOS and Linux, require you to use python3 to explicitly reference Python 3. This is because most modern computers come with both Python 2 and Python 3 installed.

python3 --version

On Windows, this command may not work unless Python was installed with python3 explicitly added.

Using python -V (Alternative syntax)

This command is a shorthand version of python --version.

python -V

The command produces the same output but behaves slightly differently in some environments. In some older environments or specific shells, the version number might be sent to stderr (standard error) instead of stdout (standard output).

To the human eye, it looks the same on the screen, but it can matter in scripts if you are trying to “pipe” that text into another file or program.

How to Check Python Version Inside Python

Sometimes you may want to check the Python version from within a script or an interactive session. This is useful when you want your code to confirm its runtime environment to help with debugging issues in your script.

You can access version details by importing the built-in sys library. The code below displays the full Python version string along with build details.

-- Check Python version
import sys
print(sys.version)

This method is useful when writing conditional logic that depends on the Python version and logging runtime information.

Checking Python Version in Virtual Environments

Since virtual environments (venv and conda) are used for specific projects, they can use a different Python version than your system’s default Python. If you create a virtual environment, it comes with a specific Python interpreter, and activating the environment switches which Python executable is used.

To confirm the active Python version on your virtual environment, first activate it, then run the following command:

python --version

If the version that appears isn’t what you expect, the environment may have been created with a different Python installation or may not currently be activated.

I recommend using our Conda Cheat Sheet when you want to have a glance at managing packages and working with the conda environment.

How to Check Python Version on Different Operating Systems

Each operating system handles Python slightly differently. Below is how to check the Python version in each:

Windows

To check the Python version in Windows, you can use:

python --version

Or:

py --version

The downsides of this method are that multiple Python installations may cause confusion, or python may not be recognized due to PATH misconfiguration. Also, the py launcher may point to a different version than python, hence fail.

macOS and Linux

For macOS and Linux, you should be aware that the system may include a preinstalled Python used internally by the OS. Also, python may refer to Python 2 or may not exist at all, while python3 usually points to the user-installed Python 3 version.

You can check the Python version in macOS or Linux using:

python --version

Or use python3 to avoid accidentally using an outdated or system-managed Python.

python3 --version

Common Problems When Checking Python Version

When checking the Python version, you may encounter some confusion, especially when multiple tools and environments are involved:

  • “Python command not found”: This usually means Python isn’t installed, or it isn’t added to your system PATH. On some systems, only python3 is available, not python.

  • Multiple Python versions installed: It’s common to have more than one Python version on the same machine. Different commands like python, python3, and py may point to different interpreters, which can make version checks seem inconsistent.

  • Command returns an unexpected version: You may be checking a different Python installation than the one you intended. This often happens when a virtual environment isn’t activated or when PATH order prioritizes another Python executable.

  • IDE vs. terminal version mismatch: Your IDE, such as VS Code or PyCharm, may be configured to use a different Python interpreter than your terminal. Code run inside the IDE uses its configured interpreter, and may not necessarily be the one returned by python --version in your command line.

Best Practices for Managing Python Versions

To avoid version-related surprises, I recommend using the checklist below:

  • Always check the Python version before installing dependencies: Always run python --version before running a command like pip install. This ensures you aren't accidentally installing libraries into the wrong version.

  • Be explicit with commands: If you know you need Python 3, use python3 instead of assuming python points to the right version.

  • Use virtual environments consistently: Use a virtual environment (venv) for every new project. This keeps your project's version and libraries isolated from the rest of your system to ensure each one uses the correct Python version and dependencies.

  • Avoid relying on system Python for projects: System-managed Python is often used by the OS and should be left untouched. Always install your own version of Python for your projects to get the intended results.

Conclusion

Being explicit about which Python version you’re running helps you avoid common setup issues, reduces confusion, and saves time when installing packages or debugging errors.

For a thorough understanding of Python, you can learn more from our Python Data Fundamentals and Python Programming Fundamentals skill tracks. Finally, I personally recommend our Python Developer career track to learn about testing code and version control in web scraping and developing packages.

Learn Python From Scratch

Master Python for data science and gain in-demand skills.
Start Learning for Free

Allan Ouko's photo
Author
Allan Ouko
LinkedIn
I create articles that simplify data science and analytics, making them easy to understand and accessible.

FAQs

What is the easiest way to check the Python version?

You can run python --version or python3 --version in the terminal to check the Python version.

Why does python show a different version than python3?

If you are using macOS or Linux systems, python and python3 commands often refer to separate Python installations.

Why does my IDE show a different Python version than my terminal?

IDEs use their own configured interpreter, which may not match the system or terminal Python.

What does “Python command not found” mean?

This command usually indicates that Python is either not installed or not included in your system’s PATH.

Can I have multiple Python versions installed at the same time?

Yes, you can have multiple Python versions installed simultaneously on the same machine.

Topics

Learn Python with DataCamp

Course

Introduction to Python

4 hr
6.7M
Master the basics of data analysis with Python in just four hours. This online course will introduce the Python interface and explore popular packages.
See DetailsRight Arrow
Start Course
See MoreRight Arrow
Related

blog

How to Install Python on macOS and Windows

Learn how to install Python on your personal machine with this step-by-step tutorial. Whether you’re a Windows or macOS user, discover various methods for getting started with Python on your machine.
Richie Cotton's photo

Richie Cotton

14 min

Tutorial

How to Upgrade Python and Pip in Windows, MacOS, and Linux

Read our step-by-step instructions for how to upgrade Pip and Python on Windows, macOS, and Linux. Keep your environment up-to-date and compatible.
Samuel Shaibu's photo

Samuel Shaibu

Tutorial

Python Setup: The Definitive Guide

In this tutorial, you'll learn how to set up your computer for Python development, and explain the basics for having the best application lifecycle.

J. Andrés Pizarro

Tutorial

How to Run Python Scripts Tutorial

Learn how you can execute a Python script from the command line, and also how you can provide command line arguments to your script.
Aditya Sharma's photo

Aditya Sharma

Tutorial

Python Tutorial for Beginners

Get a step-by-step guide on how to install Python and use it for basic data science functions.
Matthew Przybyla's photo

Matthew Przybyla

Tutorial

Virtual Environment in Python

In this tutorial, you'll learn about the Virtual Environment and two different ways of creating it.

Olivia Smith

See MoreSee More