Python is a programming language you run through a command-line interface, not a graphical application you click to open

Python does not have a window or icon to double-click. Instead, you type commands into a terminal or command prompt to run Python code. On Windows, this means opening Command Prompt or PowerShell. On Mac or Linux, you open Terminal. Once the command-line window is open, you type python or python3 and press Enter to start an interactive Python session where you can type commands directly.

If you have not installed Python yet, you need to download it from python.org first. The installation process differs slightly between Windows, Mac, and Linux, but all three versions are free. After installation, the command-line method is the standard way to use Python, whether you are running a single command or executing a saved file.

Key Takeaways

  • Python runs through a command-line interface (Terminal on Mac/Linux, Command Prompt on Windows), not through a clickable application window.
  • Type python3 in your command line and press Enter to start an interactive Python session where you can type code directly.
  • To run a saved Python file, type python3 filename.py in the command line from the folder where the file is stored.
  • If the python or python3 command does not work, Python is not installed or not added to your system path, and you need to install it from python.org first.
  • Code editors like Visual Studio Code or PyCharm provide a graphical interface for writing Python code, but they still use the command line to run it.

Opening Python on Windows

On Windows, open Command Prompt by pressing the Windows key, typing cmd, and pressing Enter. Alternatively, press Windows key + R, type cmd, and click OK. Once the black command window opens, type python3 and press Enter. If Python is installed correctly, you will see the Python version number and a >>> prompt, which means Python is ready for you to type commands.

If you see an error message saying "python3 is not recognized as an internal or external command", Python is either not installed or not added to your system path. Download Python from python.org, run the installer, and make sure to check the box that says "Add Python to PATH" during installation. After reinstalling, close and reopen Command Prompt and try again.

Some Windows systems use python instead of python3. If python3 does not work, try typing python and pressing Enter. Both commands do the same thing on most Windows installations.

Opening Python on Mac and Linux

On Mac, open Terminal by pressing Command + Space, typing terminal, and pressing Enter. On Linux, open Terminal from your applications menu or by right-clicking on the desktop and selecting "Open Terminal Here". Once Terminal is open, type python3 and press Enter. You will see the Python version and the >>> prompt if Python is installed.

Mac and Linux systems almost always use python3 rather than python. If you type python alone, you may get an older version of Python (version 2) that works differently. Always use python3 on these systems unless you have a specific reason not to.

If the command does not work on Mac, Python may not be installed. The easiest way to install it is through Homebrew, a package manager for Mac. Type brew install python3 in Terminal and press Enter. On Linux, use your system's package manager: apt install python3 on Ubuntu or Debian, or yum install python3 on Red Hat or CentOS.

Running a Python file instead of typing commands

If you have saved Python code in a file (with a .py extension), you do not need to type each command manually. Instead, open your command line, navigate to the folder where the file is stored, and type python3 filename.py, replacing "filename" with the actual name of your file. Press Enter, and Python will run the entire file and show you the results.

To navigate to the correct folder in Command Prompt or Terminal, use the cd command. For example, if your file is on your Desktop, type cd Desktop and press Enter. If you are unsure of the full path, you can drag the folder into the command-line window and it will paste the path automatically.

If you get an error saying "No such file or directory", you are either in the wrong folder or the filename is spelled differently. Type ls on Mac or Linux, or dir on Windows, to see all files in the current folder and verify the exact spelling.

Using a code editor to write and run Python

Writing Python code directly in the command line works for short scripts, but most people use a code editor for larger projects. Popular free options include Visual Studio Code, PyCharm Community Edition, and IDLE (which comes with Python). These editors provide syntax highlighting, error checking, and a built-in way to run your code without typing commands manually.

Visual Studio Code is lightweight and works on Windows, Mac, and Linux. Download it from code.visualstudio.com, install the Python extension from the Extensions marketplace, and you can write and run Python files with a single click. PyCharm is heavier but includes more Python-specific features. IDLE is the simplest option and requires no additional download—it comes with Python and opens from your applications menu.

Even when using a code editor, the editor is still calling the command line behind the scenes to run your code. Understanding how to run Python from the command line directly is useful when the editor is not available or when you need to troubleshoot why code is not running.

Exiting Python and returning to the command line

When you are in an interactive Python session (the one that started with the >>> prompt), you are inside Python and cannot use regular command-line commands. To exit Python and return to your normal command prompt, type exit() and press Enter, or press Ctrl + D on Mac and Linux, or Ctrl + Z followed by Enter on Windows.

If you run a Python file with python3 filename.py, Python runs the file and automatically returns you to the command prompt when it finishes. You do not need to exit manually in that case.

Frequently Asked Questions

What is the difference between python and python3?

Python 2 is an older version that is no longer supported. Python 3 is the current version and the one you should use. On most systems, python refers to Python 2 and python3 refers to Python 3. Always use python3 unless you have a specific reason to use the older version.

Do I need to install anything else besides Python to run code?

For basic Python, no. The Python installation includes everything you need to run standard Python code. Some projects use external libraries that require separate installation, but those are optional and only needed for specific tasks. You can start writing and running Python immediately after installation.

Why does my Python command not work even though I installed Python?

Python is likely installed but not added to your system path, which tells your computer where to find the Python program. Reinstall Python and make sure to check "Add Python to PATH" during installation on Windows. On Mac and Linux, use your package manager to install Python, which handles the path automatically.

Can I run Python without opening the command line?

Not directly. Python always runs through a command-line interface, even when you use a code editor. The editor hides the command line from view, but it is still there. Some online Python environments like replit.com let you write and run Python in a web browser without installing anything, but that is a different setup from running Python on your own computer.

What should I do if I see an error when I try to run a Python file?

Check three things: first, verify you are in the correct folder by typing ls or dir to see the files. Second, make sure the filename spelling matches exactly, including the .py extension. Third, read the error message—it usually tells you what went wrong and which line of code caused the problem. If the error mentions a missing module, you may need to install an external library.