How to Check Python Version in Windows, Mac & Linux

Posted in Python by Dirk - last update: Jan 10, 2024

Checking the Python version that is installed is important for maintaining compatibility, ensuring optimal performance, and addressing potential issues in your Python projects.

  • Compatibility: different projects and libraries may have compatibility constraints with specific Python versions. Checking the installed Python version ensures that you are using a version compatible with your project requirements.

  • Feature Availability: new features and improvements are introduced with each Python version. By knowing the installed version, you can take advantage of the latest features or ensure compatibility with projects that rely on specific features introduced in a particular Python version.

  • Deprecation Warnings: older Python versions may have deprecated features that are no longer recommended for use. Checking the Python version can help identify deprecated features and prompt you to update your code accordingly.

  • Debugging and Troubleshooting: if you encounter issues or unexpected behavior in your Python scripts or applications, knowing the Python version can be a crucial piece of information for debugging. Some issues may be specific to certain Python versions, and troubleshooting becomes more effective when you know the context.

  • Library and Framework Compatibility: various Python libraries and frameworks may have specific version requirements. Checking the Python version ensures compatibility with these dependencies, preventing potential issues during development or execution.

  • Virtual Environments: when working with virtual environments, you might want to verify the Python version within a specific environment to ensure consistency across different projects or to match the requirements of a particular project.

  • Upgrading or Installing Packages: before upgrading or installing Python packages, it’s advisable to check the Python version to ensure that the packages are compatible. Some packages may require a minimum or specific Python version to function correctly.

Which versions of Python exist?

Python has two major versions that are widely in use: Python 2 and Python 3.

However, it’s important to note that Python 2 has reached its end of life and is no longer officially supported. Therefore, it is strongly recommended to use Python 3 for all new projects and migrations.

Within Python 3, there are various releases with new features, optimizations, and bug fixes. It’s advisable to use the latest stable release for new projects, as it incorporates improvements and security updates.

For the most up-to-date information on Python versions, you should visit the official Python website or check the Python Software Foundation’s download page.

If the python or python3 command is not recognized, you may need to add the Python installation directory to your system’s PATH environment variable.

How to check the Python version in Windows

Python is not preinstalled on Windows systems. If you’ve previously used Python but can’t recall the version, it’s simple to verify the installed version.

Command Prompt:

Open the Command Prompt and type the following command:


python --version

PowerShell

Open PowerShell and use the following command:


python --version

How to Check Python Version in MacOS

On a Mac, verify the Python version by executing the following command in the terminal:


python --version

or


python --V

If you have both Python 2 and Python 3 installed on your system, you may need to use python3 or python3.x to check the version of Python 3.


python3 --version

or


python3 --V

How to Check Python Version in Linux

Checking the Python version on Linux is straightforward. Many contemporary Linux distributions include Python by default. To determine the installed version, open a terminal window and execute the following command:


python3 --version

Given that Python 3 is typically the default version on modern Linux systems, we use “python3” in the command. However, if you utilize Python 2 for certain applications, you can exclude the “3” from the command to get the installed Python 2 version.

Other articles