How to Check Installed Python Version

Mateen Kiani

Mateen Kiani

Published on Sat Aug 02 2025·3 min read

how-to-check-installed-python-version

Introduction

Python is a staple tool for developers, data scientists, and automation experts. Yet, a small but critical detail often slips under the radar: knowing exactly which Python version you’re running. Why does this matter? You might install a library that requires Python 3.8, or debug a script that behaves differently on 3.9.

So how can you quickly confirm the Python version on your machine or within a virtual environment? Understanding this helps you avoid compatibility headaches, ensure reproducible setups, and make informed decisions when upgrading or deploying code.

Why Python Version Matters

Every Python release brings new language features, performance improvements, and security patches. A script written for Python 3.6 could break on 3.9 if it uses deprecated behavior. Similarly, a package published for Python 3.10 may not install on older interpreters.

Keeping track of your Python version ensures:

  • Compatibility with dependencies
  • Correct environment setup for teams
  • Predictable behavior across systems

Tip: Always note the exact minor and patch level when sharing environment details. It saves hours of debugging later.

Checking Version in Terminal

On macOS and Linux, open your terminal and run:

$ python --version
# or
$ python3 --version

You’ll see output like:

Python 3.9.7

If you have both Python 2 and 3 installed, python may point to 2.x. Always try python3 to confirm your Python 3 interpreter.

Using Python in Scripts

Inside a Python script, you can programmatically retrieve the version:

import sys
print(sys.version)
# or for structured info
print(sys.version_info)

The sys.version_info tuple gives you major, minor, and micro numbers:

# Example output
sys.version_info(major=3, minor=9, micro=7, releaselevel='final', serial=0)

Use these values for runtime checks:

if sys.version_info < (3, 8):
raise RuntimeError("Python 3.8 or higher is required.")

Checking on Windows

Windows users can open Command Prompt or PowerShell:

C:\> python --version
Python 3.8.10

If you see an error, you may need to add Python to PATH. During installation, select the “Add to PATH” option, or update your environment variables manually.

Virtual Environment Version

Virtual environments let you isolate projects with different Python versions:

  1. Create venv with a specific interpreter: bash $ python3.8 -m venv myenv
  2. Activate it: bash $ source myenv/bin/activate # macOS/Linux $ .\myenv\Scripts\activate # Windows
  3. Check version inside: bash (myenv) $ python --version

Tip: Use tools like pyenv or switch Python versions to manage multiple interpreters seamlessly.

Troubleshooting Common Issues

  • Wrong interpreter: Ensure your IDE or editor points to the right Python binary.
  • PATH conflicts: Clean up old entries or reorder your PATH so the desired Python appears first.
  • Alias confusion: On Linux, check if python has been aliased to python3 or vice versa (alias python=python3).

Bulletproof your setup:

  • List installed Pythons: ls /usr/bin/python*
  • Verify shebang in scripts: #!/usr/bin/env python3
  • Keep a project README with version instructions

Conclusion

Knowing your installed Python version is a simple but powerful practice. It prevents dependency clashes, ensures consistent environments, and helps you leverage new language features without surprises. Whether you’re on Windows, macOS, or Linux, the --version flag and sys.version_info have you covered. Pair these with virtual environments and version managers to streamline your workflow.

Now you’re ready to confirm your Python setup at a glance—no more guesswork, just confidence in your development environment.


Mateen Kiani
Mateen Kiani
kiani.mateen012@gmail.com
I am a passionate Full stack developer with around 4 years of experience in MERN stack development and 1 year experience in blockchain application development. I have completed several projects in MERN stack, Nextjs and blockchain, including some NFT marketplaces. I have vast experience in Node js, Express, React and Redux.