Concepts / Configuring the PATH Variable

Configuring the PATH Variable

Open the Windows command line by clicking Start, then Run, typing cmd, and pressing Enter

  • Programming

From Windows to Python

Once Python is installed and the PATH variable is properly configured, you can start Python directly from the Windows command line. This creates a short sequence of environments: Windows provides the command-line terminal, the terminal receives the python command, and the Python interpreter starts and presents the >>> prompt. The main skill is recognizing which environment is active at each stage.

What do you think happens?

After entering python at the Windows command prompt, which prompt should appear when the interpreter is ready?

  • C:\Users\YourName>
  • >>>
  • Run
  • cmd
Reveal answer

Answer: >>>

The three greater-than symbols indicate that the Python interpreter is active and waiting for Python code. The Windows command-line prompt is different and expects Windows commands.

Opening the Command Line

Begin by opening the Windows command-line terminal. Click the Start button, click Run, type cmd in the Run dialog, and press Enter. A new window opens with the Windows command prompt and a blinking cursor ready for input.

  1. Click Start.
  2. Click Run.
  3. Type cmd in the dialog box.
  4. Press Enter.
  5. Wait for the Windows command prompt window to open.

How PATH Finds Python

When you type python at the Windows command prompt and press Enter, Windows uses the configured PATH variable to find and execute the Python interpreter. If the PATH variable is properly configured, the command can launch Python directly from the command line. The result is a transition from the Windows terminal environment into the Python interpreter.

enterlocatefind and executedisplayWindows commandpromptC:\Users\YourName>pythoncommandPATH variableconfigured locationsPython interpreterversion information>>>ready for Python code
How does Windows use the configured PATH variable to locate and launch Python when the python command is entered?

PATH configuration matters because it allows the python command to launch the interpreter directly from the Windows command line. The visible sign of the transition is the change from the Windows command-line prompt to the Python prompt.

Launching and Checking Python

Starting an Interactive Python Session

You have opened the Windows command prompt and want to start Python directly from it.

Enter the launch command: At the Windows command prompt, type python and press Enter. Windows uses the configured PATH variable to find and execute the Python interpreter.

Observe the startup information: Python displays version information. The exact version number depends on the Python version installed on the system.

Check the prompt: Look for >>>. This shows that the Python interpreter is active and ready to accept Python code.

Recognize the environment change: The >>> prompt means that input is now interpreted as Python code rather than as a Windows command.

Python has started successfully when version information is displayed and the >>> prompt appears.

EnvironmentPromptExpected input
Windows command lineC:\Users\YourName> or similarWindows commands and commands that launch applications
Python interpreter>>>Python code

The prompt identifies which environment will interpret what you type.

Leaving the Interpreter

After Python has started, you are inside the interpreter rather than directly at the Windows command line. To return to the Windows command line, type exit() at the >>> prompt and press Enter. The prompt changes back to a Windows command-line prompt such as C:\Users\YourName> or a similar prompt.

Mistakes with the Two Prompts

  • Typing python before opening the Windows command-line terminal

    The described process begins at the Windows command prompt. Without that terminal, there is no command-line environment in which to enter python.

    Fix: Open the terminal first by clicking Start, clicking Run, typing cmd, and pressing Enter.

  • Assuming that the Windows prompt and the Python prompt are the same

    The Windows command line and the Python interpreter are distinct environments that expect different kinds of input.

    Fix: Use the Windows prompt for Windows commands and use >>> for Python code.

  • Assuming Python is ready without checking the startup signs

    The source identifies version information and >>> as the visible signs that the interpreter has started correctly.

    Fix: Verify both the version information and the >>> prompt before entering Python code.

  • Trying to leave Python by treating exit() as a Windows command

    The instruction to return to the Windows command line applies to the Python interpreter environment.

    Fix: At the >>> prompt, type exit() and press Enter.

Guided Terminal Check

EASY

Perform the complete sequence on a Windows system: open the Run dialog through Start, type cmd, press Enter, type python at the Windows command prompt, and press Enter. Record which prompt appears after the Python version information. Then identify which environment is active and use the appropriate command to return to the Windows command line.

Hints
  • The Windows prompt looks similar to C:\Users\YourName>.
  • The Python prompt consists of three greater-than symbols.
  • The command used to return from Python is exit().

PATH Configuration Takeaways

  1. Open the Windows command-line terminal through Start, Run, cmd, and Enter.
  2. Type python at the Windows command prompt and press Enter to launch the interpreter when PATH is properly configured.
  3. Confirm startup by looking for Python version information and the >>> prompt.
  4. Remember that the Windows command-line prompt expects Windows commands, while >>> expects Python code.
  5. Use exit() at the Python prompt to return to the Windows command line.

Key Takeaways

  • The Run dialog provides a direct way to open the Windows command-line terminal.
  • A properly configured PATH variable allows the python command to launch the Python interpreter from that terminal.
  • Python startup is confirmed by version information and the >>> prompt.
  • The Windows command line and the Python interpreter are separate environments with different prompts and expected inputs.
  • Typing exit() at the Python prompt returns control to the Windows command line.