askvity

How to Check Python Version?

Published in Python Version 3 mins read

To check the Python version installed on your system, the most common and direct method is using your computer's command line or terminal.

You can quickly find your Python version by opening a command prompt, terminal, or the integrated terminal in your IDE and running a simple command.

Checking Python Version via Command Line or Terminal

This method works universally across different operating systems like Windows, macOS, and Linux.

  1. Open your terminal or command prompt:

    • Windows: Search for "cmd" or "Command Prompt" in the Start menu.
    • macOS: Search for "Terminal" in Spotlight (Cmd + Space) or find it in Applications > Utilities.
    • Linux: Open your preferred terminal application (e.g., GNOME Terminal, Konsole, xterm).
  2. Run the Python version command:
    Type one of the following commands and press Enter:

    • python --version
    • python -V

    (Note: On some systems, particularly macOS and Linux, you might need to use python3 --version or python3 -V if you have both Python 2 and Python 3 installed, and python defaults to Python 2).

  3. View the output:
    The terminal will display the installed Python version number, such as Python 3.9.7 or Python 2.7.18.

Checking in Integrated Development Environments (IDEs)

As mentioned in the reference, checking the version within an IDE like Visual Studio Code or PyCharm is straightforward.

  • Open the integrated terminal within your IDE.
  • Run the command python --version or python -V in the integrated terminal.
  • The terminal will display the installed Python version.

This is convenient because it often shows the version associated with the project or virtual environment you are currently working in within the IDE.

Alternative Methods

While the command line is the primary method, here are a couple of other ways you might encounter or need to use:

  • Using Python Script: You can run a short Python script to print the version information.

    import sys
    print(sys.version)

    Save this as a .py file (e.g., check_version.py) and run it from your terminal using python check_version.py.

  • Within a Python Interactive Session:
    Open the Python interactive interpreter by typing python (or python3) in your terminal and pressing Enter. Once the prompt (>>>) appears, type:

    import sys
    print(sys.version)

    Press Enter, and the version details will be displayed. Type exit() and press Enter to leave the interactive session.

Command Options Summary

Here's a quick table summarizing the main terminal commands:

Command Description Output Example
python --version Standard command to display Python version. Python 3.10.2
python -V Shorthand for --version. Python 3.10.2
python3 --version Used when python defaults to Python 2. Python 3.11.1
python3 -V Shorthand for python3 --version. Python 3.11.1

Understanding your Python version is crucial for compatibility with libraries and frameworks, managing environments, and troubleshooting issues.

Related Articles