How To Open Python on Windows, Mac, Linux

You’ll now learn to open Python on Linux, Windows, and MacOS. First of all, you should know that there are two ways of using Python:

  1. Start an interactive shell, also called a REPL, short for read-evaluate-print-loop.
  2. Start a Python program that you stored in one or more files with the .py extension.

This tutorial will start with the interactive shell because it’s ideal for exploring the language. But at some point, using the REPL will not be enough, and you’ll have to start creating Python files instead.

If you installed Python on your local machine, you first need to start a terminal or command prompt before you can start the Python interactive shell. On all platforms, you should be able to start Python 3 with the command python3 (or sometimes just python). Just be sure you are running Python 3, not 2, because some systems can have both versions installed.

How to open Python on Windows

On Windows, you can start Python from a terminal. I highly recommend you follow my Computer Fundamentals course, in which I explain all the basics you need to know before you begin programming! It does a great job of introducing you to files, folders, the basics of how a computer works, and using the command line.

To start PowerShell, hit the Windows key and start typing PowerShell. You can use the ‘Command Prompt’ program if you don’t have PowerShell. Once you are in a shell or command prompt, enter one of the following commands (try them in the given order):

  1. py
  2. python3
  3. python

The first command (py) is a wrapper script that allows you to start the latest version of Python. If it works, great. Just remember that I’ll often refer to python or python3 in the tutorial. You will need to use py in those cases.

Python started from Windows PowerShell
Python started from Windows PowerShell

How to open Python on Mac

On MacOS, search for a program called terminal. You can do so by pressing the command key (⌘) + space bar. This will open up the Spotlight search bar, in which you start typing the word ‘terminal’.

Once inside the terminal, enter python3 to open the Python REPL. If that doesn’t work, try entering python instead (without the 3).

I highly recommend you follow my Computer Fundamentals course, in which I explain all the basics you need to know before you begin programming! It does a great job of introducing you to files, folders, the basics of how a computer works, and using the command line.

How to open Python on Linux

On Linux, you first need to start a terminal. This can often be done with the shortcut ctrl + alt + T. Alternatively, you can search for the terminal program in your start menu. The name and where to find it differ from distribution to distribution. Once you have a terminal running, enter python3 to start the Python REPL. If that doesn’t work, try python instead (without the 3).

I highly recommend you follow my Computer Fundamentals course, in which I explain all the basics you need to know before you begin programming! It does a great job of introducing you to files, folders, the basics of how a computer works, and using the command line.

Python running in a Linux terminal

How to close the REPL

Now that you know how to open the REPL, it would be nice to close it properly, too. If you simply close the terminal window by pressing the close button, you will be able to close the REPL inside it as well. However, it won’t be a clean exit; your terminal will usually warn you about this. So, how do you exit the REPL cleanly?

What works on every OS is the following Python command: exit()

You can also use a little trick if you’re on Linux or MacOS. By pressing control + d, the REPL will exit immediately. Control + d sends the ‘end of file’ character the to terminal, and the REPL interprets this as a request to exit Python. On Windows, you can do something similar by pressing control + z and then hitting enter.

Get certified with our courses

Learn Python properly through small, easy-to-digest lessons, progress tracking, quizzes to test your knowledge, and practice sessions. Each course will earn you a downloadable course certificate.

Related articles