How-to-Check-Python-Version-on-Windows-Mac-and-Linux
How to Check Python Version on Windows, Mac, and Linux

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

Python is one of the most popular programming languages, widely used for automation, web development, data science, and artificial intelligence. Before running Python scripts or installing libraries, it’s crucial to check Python version on your system to ensure compatibility.

Different operating systems have different ways to verify the installed Python version. This guide will walk you through how to check Python version on Windows, Mac, and Linux using various methods.


How to Check Python Version on Windows

1. Using Command Prompt (CMD)

The quickest way to check Python version on Windows is through the Command Prompt.

Steps to check Python version using CMD:

  1. Press Win + R, type cmd, and press Enter to open the Command Prompt.
  2. Type the following command and press Enter:

python –version

Or

python -V

The installed Python version will be displayed on the screen.

If you have Python 3 installed, but the above command doesn’t work, try:

python3 –version

2. Using PowerShell

Windows PowerShell is another tool to check Python version.

Steps to check Python version using PowerShell:

  1. Press Win + X, then select Windows Terminal (PowerShell).
  2. Type the following command and press Enter:

python –version

  1. The Python version will be displayed instantly.

3. Using a Python Script

You can also use a Python script to check Python version programmatically.

Steps to check Python version using a script:

  1. Open Notepad or any text editor.
  2. Write the following Python code:

import sys
print(“Python Version:”, sys.version)

Save the file as check_version.py.Open CMD or PowerShell, navigate to the file location, and run:

python check_version.py

  1. The output will display your Python version.

How to Check Python Version on Mac

1. Using Terminal

Mac users can quickly check version using the Terminal.

Steps to check Python version on Mac:

  1. Press Command + Space, type Terminal, and hit Enter.
  2. Type the following command and press Enter:

python3 –version

The installed Python version will be displayed.

Note: On older Mac versions, Python 2 may still be available. To check Python 2, use:

python –version

2. Using a Python Script

You can also use a Python script to check Python version on Mac.

Steps to check version using a script:

  1. Open a text editor and write the following code:

import platform
print(“Python Version:”, platform.python_version())

Save the file as check_version.py.

Open Terminal, navigate to the file location, and run:

python3 check_version.py

  1. The script will output your Python version.

How to Check Version on Linux

1. Using Terminal

Most Linux distributions come with Python pre-installed. To check version, use the Terminal.

Steps to check version on Linux:

  1. Open Terminal (Ctrl + Alt + T).
  2. Type one of the following commands and press Enter:

python3 –version

or

python –version

  1. The installed Python version will be displayed.

2. Checking the Installed Python Packages

You can get more details about your Python installation using a command.

Steps to check full version details:

  1. Open Terminal.
  2. Run the following command:

python3 -c “import sys; print(sys.version)”

This command will display the Python version along with additional details.


How to Check If Multiple Python Versions Are Installed

If you have multiple versions of Python installed, you can check them using the following commands:

  • On Windows:

where python

On Mac/Linux:

which python

List all installed Python versions (Windows only):

py -0

This will help you identify which Python version is set as default.


How to Update Python to the Latest Version

If you find that your Python version is outdated, you can update it easily.

Updating Python on Windows

  1. Go to the official Python website: https://www.python.org/downloads/.
  2. Download the latest version for Windows.
  3. Run the installer and select Upgrade Now to update Python.

Updating Python on Mac

  1. Open Terminal.
  2. Use Homebrew to update Python:

brew install python

Verify the update:

python3 –version

Updating Python on Linux

  1. Open Terminal.
  2. Use the package manager for your distribution:
  3. Ubuntu/Debian:

sudo apt update && sudo apt install python3

Fedora

sudo dnf install python3

Arch Linux:

sudo pacman -S python


Common Issues and Troubleshooting

Sometimes, checking the Python version may result in errors. Here are common issues and how to fix them:

  1. Python not recognized as a command:
    • Ensure Python is added to the system’s environment variables (Windows).
    • Use python3 instead of python on Mac/Linux.
  2. Multiple Python versions conflicting:
    • Use which python or where python to check installed versions.
    • Set the default Python version using alias commands in .bashrc or .zshrc.
  3. Command not found:
    • Reinstall Python and ensure it’s properly configured.

Conclusion

Knowing how to check version is essential for debugging, installing libraries, and ensuring compatibility with projects. Whether you’re using Windows, Mac, or Linux, there are multiple ways to verify your installed Python version. Keeping Python updated will help you stay secure and take advantage of the latest features.

If you found this guide helpful, share it with others and keep exploring the power of Python! 🚀

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *