How to Check Python Installation on Windows and Mac

Ensure Python is installed on your system with our easy-to-follow guide. Learn how to verify Python installation on Windows and Mac, including searching for Python in the Start menu and using the Command Prompt. Get step-by-step instructions for checking your Python setup.



Python Installation

Many PCs and Macs come with Python pre-installed. To check if Python is installed on your system, follow these steps:

For Windows:

  1. Search for "Python" in the Start menu.
  2. Or open the Command Prompt (cmd.exe) and type:
  3. 
    C:\Users\Your Name>python --version
    

For Linux or Mac:

  1. Open the command line (Linux) or Terminal (Mac) and type:
  2. 
    python --version
    

If Python is not installed, you can download it for free from the official Python website.

Python Quickstart

Python is an interpreted programming language, meaning you write Python (.py) files in a text editor and then run these files using the Python interpreter.

To run a Python file from the command line, use:


C:\Users\Your Name>python helloworld.py

Where "helloworld.py" is the name of your Python file.

Let's create our first Python file, named helloworld.py, in any text editor:

Save your file, open your command line, navigate to the directory where you saved your file, and run:


C:\Users\Your Name>python helloworld.py

The output should be:

helloworld.py

print("Hello, World!")

Congratulations, you have written and executed your first Python program!

Checking Python Version

To check the Python version in the editor, you can import the sys module:


import sys

print(sys.version)
Output

3.8.2 (default, Mar 13 2020, 10:14:16)
[GCC 9.3.0]

You will learn more about importing modules in the Python Modules chapter.

The Python Command Line

Sometimes, it's quicker to test a small amount of code directly in the command line rather than writing it to a file. Python can be run as an interactive command line:


C:\Users\Your Name>py
C:\Users\Your Name>python

If the python command doesn't work, try py:

From there, you can write any Python code, including the Hello, World! example:


C:\Users\Your Name>python
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello, World!")
Hello, World!

To exit the Python command line interface, type:


exit()