Chapter 01

Installing Python and running your first program

Install Python on Windows, confirm from the terminal that it actually works, and run your first Python file on your own machine.

25 minPython 3.12
  1. 1Encounter
  2. 2Understand
  3. 3Worked
  4. 4Predict
  5. 5Apply
  6. 6Stretch

The problem we are solving

You want to learn Python. There are plenty of sites where you can type code into a browser — but nobody writes code in a browser at work. At work, Python is installed on your own machine, you open a terminal, you run commands, and you save files and execute them.

So we will work that way from day one. By the end of this mission you will have real Python on your computer, and you will have run a program with it.

By the end of this mission you can

  • Install Python 3.12 on Windows
  • Verify from the terminal that the installation actually works
  • Write a .py file and run it
  • Recognise and fix the single most common installation mistake

Prerequisites: none. This is the first mission.


Step 1 — Download Python

Go to python.org/downloads and use the large button to download the latest 3.12 release.

Do not install from the Microsoft Store. On Windows, typing python often opens the Store instead. The Store build runs in a restricted environment, which causes strange failures later when you install packages or write files next to your code. Use python.org.

Step 2 — Tick one box during installation

When the installer opens, there is a small checkbox at the bottom of the very first screen:

python
[ ] Add python.exe to PATH

Tick it. This is the most important step in the mission.

PATH is the list Windows searches to decide which programs can be run from anywhere. Without it Python still installs, but typing python in a terminal gets you an error — Windows simply does not know where Python went.

Then press Install Now.

Step 3 — Verify

When the installer finishes, open a new terminal. Press Start, type powershell, and open it.

Opening a new terminal matters. Any terminal that was already running still remembers the old PATH and will not see the new installation.

Run:

text
python --version

You should see something like:

text
Python 3.12.7

The final number may differ — that is fine. As long as it says 3.12, you are set.

Step 4 — Your first program

Make a folder, say D:\python-lab. Create a file in it called hello.py containing:

python
language = "Python"
print("Hello from", language)
print("2 + 3 =", 2 + 3)

Now move to that folder in the terminal and run the file:

text
cd D:\python-lab
python hello.py

Output:

text
Hello from Python
2 + 3 = 5

Your computer just ran a Python program. Not a browser, not a website — your own machine.


When it breaks

Typing python opens the Microsoft Store Python is not on PATH, so Windows runs its own shortcut instead. Run the installer again, choose Modify, and tick "Add python.exe to PATH".

python : The term 'python' is not recognized... Same cause, same fix. You can also check whether py --version works — py is the Windows Python launcher and works even when PATH does not.

python hello.py says can't open file You are in the wrong folder. Run dir and check that hello.py is listed. If it is not, cd to the right folder.

The file is actually named hello.py.txt Windows hides file extensions by default. In File Explorer turn on View → Show → File name extensions, then rename the file.