Understanding the Terminal and Command Line
Verification confirms that Python is installed on your Mac and accessible from the terminal.
From Desktop to Command
Before writing Python programs, you need to confirm two things: Python is installed on your Mac, and the system can find it when you enter a command. Installation and verification are different steps. Verification is the bridge between installing Python and actually using it.
The Terminal is macOS's command-line interface. Instead of choosing an application or action through a graphical window, you type a command and press Enter. The Terminal passes that command to the system, and the result appears in the same window. When the Terminal is ready for a command, its prompt commonly ends with a dollar sign or percent sign.
Opening the Terminal
- From the macOS desktop, press Command + Space to open Spotlight search.
- Type Terminal into the search field.
- Open the Terminal application from the search results.
- Find the command prompt in the Terminal window. It commonly ends with a dollar sign or percent sign.
Running the Verification
At the regular Terminal prompt, run python3 and press Enter. This asks the system to start Python 3. A successful result shows Python version information and then the Python interactive prompt, written as >>>.
A Successful Verification
Determine whether the displayed result shows that Python is installed and accessible.
Command: The command entered at the regular Terminal prompt is python3.
Version line: The output includes a Python version number, such as Python 3.9.7. The version line confirms which Python version has started.
Interactive prompt: The >>> prompt appears after the version information. This means Python is running and waiting for Python code.
Python has been successfully verified as installed and accessible from the Terminal.
Reading the Result
The first line typically contains the Python version number. Additional lines may identify the compiler used to build Python, the date it was built, and license information. The most important confirmation is the >>> prompt at the end. It tells you that the Python interpreter is now running and waiting for Python code.
Choosing python3
On many Mac systems, both python and python3 may be available. The distinction exists because macOS historically shipped with Python 2, while Python 3 could also be installed by the user or by another application. The python command often points to Python 2, which is outdated and no longer supported. The python3 command points to Python 3, the current and actively maintained version described in the source material.
Use python3 for modern Python development and for installation verification. This makes your intended Python version explicit instead of relying on what the python command happens to point to on a particular Mac.
Leaving the Interpreter
After verification, the >>> prompt means that you are inside the Python interactive prompt rather than at the regular Terminal prompt. To return to the regular Terminal prompt, type exit() and press Enter, or press Control + D.
Open Terminal with Spotlight, run python3, and inspect the result. Identify the version information and the >>> prompt. Then leave the Python interactive prompt using exit().
Hints
- Press Command + Space to open Spotlight.
- A successful verification includes a Python version number.
- The >>> prompt means Python is running and waiting for Python code.
- Use exit() or Control + D to return to the regular Terminal prompt.
Assuming that opening Terminal proves Python is installed.
The Terminal is only the command-line interface. Installation still needs to be verified.
Fix:
Run python3 and look for the Python version and >>> prompt.Using python without considering which Python version it launches.
Python 2 is outdated and no longer supported.
Fix:
Use python3 for modern Python work.Treating the >>> prompt as another regular Terminal prompt.
The >>> prompt means Python is running and waiting for Python code.
Fix:
Use exit() or Control + D to return to the regular Terminal prompt.Ignoring a command not found message.
Python may not be installed, or the system may not be able to find it in its search path.
Fix:
Install Python before continuing, consulting the official Python installation guide or a system administrator.
Key Takeaways
- Use Command + Space to open Spotlight, then search for and open Terminal.
- Run python3 at the Terminal prompt to verify that Python 3 is installed and accessible.
- A Python version line followed by >>> confirms that the Python interpreter is running.
- The python command often refers to Python 2 on macOS, while python3 refers to Python 3.
- Exit the Python interactive prompt with exit() or Control + D.
Key Takeaways
- The Terminal is macOS's command-line interface for entering commands and viewing results.
- Spotlight opens quickly with Command + Space and can be used to find Terminal.
- Running python3 and seeing a Python version plus the >>> prompt confirms successful access to Python.
- Use python3 rather than python for modern Python work because python often points to outdated Python 2 on macOS.
- Use exit() or Control + D to leave the Python interactive prompt.