2. Python Setup

What you will learn

  • How to install Python
  • How to check it works
  • How to run a file and use interactive mode
  • How to choose an editor

Install Python

  1. Open python.org and go to the Downloads page.
  2. Download the latest Python 3 installer for your system.
  3. Run the installer.
    • On Windows, tick “Add python.exe to PATH” at the bottom of the first screen before clicking Install Now. This lets you run Python from any folder.
    • On macOS, open the downloaded package and follow the steps.
  4. When it finishes, close the installer.

On Linux, Python 3 is usually already installed. If not, use your system’s package manager.

Only download Python from python.org or your operating system’s official store. Installers from other sites may be unsafe.

Check the installation

Open a terminal:

  • Windows: press the Windows key, type cmd, and press Enter.
  • macOS: open Terminal from Applications, Utilities.

Terminal command

python --version

What you should see (your number will differ)

Python 3.x.x

If that does not work, try python3 --version (common on macOS and Linux) or py --version (Windows). Use whichever one answers, and use the same word in the commands below.

Interactive mode

Type python (or python3) and press Enter. You will see a prompt that looks like >>>. Type a line and press Enter to run it at once.

Python code: typed at the prompt

>>> 2 + 3
5
>>> print("Hello")
Hello
>>> exit()

Type exit() to leave. Interactive mode is perfect for quick experiments. For anything longer, use a file.

Write and run a file

  1. Create a folder, for example python-practice.
  2. Open a text editor and create a file named hello.py inside it.
  3. Type this and save:

Python code: hello.py

name = "Sam"
print("Hello,", name)
print("Welcome to Python!")
  1. Open a terminal in that folder. In Windows File Explorer, click the address bar, type cmd, and press Enter. In VS Code, use Terminal → New Terminal.
  2. Run the file:

Terminal command

python hello.py

Output

Hello, Sam
Welcome to Python!

Notice that print("Hello,", name) puts a space between its values for you.

Choosing an editor

  • IDLE: a simple editor that comes with Python. Search for it in your Start menu. Good for a first day.
  • Visual Studio Code (free): popular and powerful. Install the Python extension from Microsoft.
  • PyCharm Community Edition (free): a full Python-focused tool.

Any plain text editor works. Do not use a word processor such as Word, because it adds hidden formatting. Save files with the .py ending, and in Windows turn on View → Show → File name extensions so a file is not secretly called hello.py.txt.

Troubleshooting

Problem Likely cause and fix
“python is not recognized” Python is not on the PATH. Re-run the installer and tick Add python.exe to PATH, or try py
“No such file or directory” or “can’t open file” The terminal is in the wrong folder, or the file name is misspelled
The Microsoft Store opens Windows is redirecting a missing command. Install Python from python.org
Wrong version shown Several versions are installed. Use python3 or py -3

Common mistakes

  • Forgetting to tick Add to PATH on Windows.
  • Running the command from a different folder from the file.
  • Saving the file as .txt.
  • Typing >>> yourself when copying examples. It is only the prompt.

Exercise

Create about-me.py that stores your name and a favourite colour in two variables, and prints one sentence using both. Run it from a terminal.

Show solution
name = "Sam"
colour = "blue"
print(name, "likes the colour", colour)

Output: Sam likes the colour blue

Knowledge check

1. How do you run hello.py from a terminal?

python hello.py (or python3 or py, depending on your system).

2. What does the >>> prompt mean?

You are in interactive mode, and Python is waiting for a line to run.

3. Which Windows installer option avoids “python is not recognized”?

Tick Add python.exe to PATH.

Summary

  • Install Python 3 from python.org, and check it with python --version.
  • Use interactive mode for quick tests, and python file.py to run a file.
  • Use a plain text editor such as IDLE or VS Code, and save with the .py ending.
Scroll to Top