, ,

Install Python and Run Your First Program (Python for Beginners, Part 2)

Install Python 3 on Windows, macOS, or Linux, confirm it from a terminal, and run your first real program from a saved file. Setup made painless.

Python for Beginners · Part 2 of 20

The first error most people meet in Python is not in their code. It shows up before they have written a single line, and it looks like this:

terminal
'python' is not recognized as an
internal or external command

That message feels like a wall. It is not. It just means the computer does not yet know where Python lives. This part gets Python installed on your machine, gets that message to go away, and ends with a real program running from a file you wrote. Twenty focused minutes, and you will be past the setup that stops a lot of people.

The short versionInstall Python 3 from the official site, tick the box that adds it to your PATH on Windows, then confirm it with one command in a terminal. After that you write a small file and run it. If you are on a college laptop with no admin rights, the same official installer has a "just for me" option that needs no admin.

You need nothing before this except a computer you can install software on and about twenty minutes. This part follows straight on from Part 1, where we ran a one line program; here you get the tools to run that same line yourself. Everything below you can type as you read. Copying works too, with one warning I will repeat later: pasted quote marks sometimes break.

Get Python onto your machine

Windows, macOS and Linux each handle this a little differently, so find your system below and ignore the other two. In every case the download comes from one place: python.org/downloads. Use the official installer, not a random bundle from a search result. The current release as you read this is Python 3.14; any 3.13 or 3.14 build is fine for this whole series.

Your systemHow to installThe command you will use
Windows 10 or 11Download the Windows installer from python.org and run itpython or py
macOSDownload the macOS installer from python.org and run itpython3
Linux (Ubuntu, Debian)Usually already there; if not, install with aptpython3

Table 1. Where to get Python and what to type once it is installed.

Windows

Go to python.org/downloads and click the yellow button that offers the latest Python for Windows. Open the file it downloads. On the very first screen of the installer there is a checkbox at the bottom that reads Add python.exe to PATH. Tick it. This one checkbox is the difference between the setup just working and that "not recognized" error above. Then click Install Now and let it finish.

PATH is simply the list of folders your computer searches when you type a command. Ticking the box adds Python to that list, so typing python anywhere finds it.

macOS

Macs ship with old Apple tools but not with a Python you should build on, so install a fresh one. Download the macOS installer from python.org and run it, clicking through the steps. When it finishes you will use the command python3, not python. On a Mac, plain python often does not exist at all, and that is normal.

Linux

Most Linux systems already include Python 3. Open a terminal and check first before installing anything. If it is missing on Ubuntu or Debian, one command fixes it:

terminal (linux)
sudo apt update
sudo apt install python3

The word sudo runs the command with administrator rights, so it may ask for your password. On Linux you also use python3 as the command.

Check that it actually worked

Before writing anything, confirm the interpreter is reachable. The interpreter is the program that reads your Python and runs it; you met it in Part 1. Open a terminal. On Windows that is the app called Command Prompt or PowerShell. On macOS it is Terminal. On Linux it is your usual terminal. Type the version command for your system:

windows
python --version
macos / linux
python3 --version

You should see something close to this, though the last number will vary:

output
Python 3.14.6

If you see a version number, Python is installed and on your PATH. You are ready. If instead you get "not recognized" on Windows or "command not found" on macOS or Linux, the interpreter is not on your PATH yet. On Windows the usual cause is the unchecked box from a minute ago; the quickest fix is to run the installer again, choose Modify, and make sure PATH is selected, or just type py --version instead, because the Windows installer also gives you a launcher called py that works even when python does not.

Read the last line firstWhen something goes wrong, Python and your terminal usually print several lines. The one that tells you what happened is almost always the last line. Train this habit now: skip to the bottom of any red or error text and read that line before anything else. It saves hours over a career.

Two ways to run Python

There are two ways to hand instructions to the interpreter, and beginners get confused when a tutorial silently switches between them. Knowing both, and when each is used, clears up a lot.

The first is the interactive prompt, also called the REPL. You type one line, press Enter, and see the result immediately. It is a scratchpad. The second is a script: you save your instructions in a .py file and run the whole file at once. That is how real programs are built and shared.

Interactive prompt (REPL) You type one line Press Enter See the answer at once >>> 2 + 2 4 Script file You save many lines in a .py file Run the whole file once python hello.py Hello, world!

Figure 1. The REPL is for quick tries. A script file is for programs you keep.

Open the REPL now. Type python on Windows or python3 on macOS and Linux, with no filename after it, and press Enter. The prompt changes to three greater-than signs:

repl
>>> 2 + 2
4
>>> print('hi')
hi

Those three signs mean Python is waiting for a line. Try a little arithmetic. When you are done, type exit() and press Enter to leave. The REPL is perfect for checking "what does this one line do", but it forgets everything when you close it. For anything you want to keep, you need a file.

Your first program in a file

Create a folder for this series so your files do not scatter. Inside it, make a new plain text file named hello.py. You can use any editor: Notepad on Windows, TextEdit on macOS in plain text mode, or a code editor like VS Code, which is free and what most people settle on. Put this single line in it and save:

hello.py
print('Hello, world!')

Now run it. In your terminal, move into the folder you saved it in using cd, which stands for change directory, then run the file. Notice the path separator differs by system: Windows uses a backslash, macOS and Linux use a forward slash.

windows
cd Documentspython-series
python hello.py
macos / linux
cd Documents/python-series
python3 hello.py
output
Hello, world!

That is a real program. You wrote it, saved it, and the interpreter ran it from top to bottom. Everything else in this series is more of this: more lines, more ideas, same loop of write, save, run.

The error you will probably hit

A very common first stumble is running the command from the wrong folder. If the terminal is not in the folder where hello.py lives, Python cannot find the file and says so:

output
python: can't open file 'hello.py':
[Errno 2] No such file or directory

Read that last line. "No such file" means Python looked and did not find hello.py where you are standing. The fix is to cd into the correct folder first, or type the full path to the file. This is not a Python fault and not a sign you did anything wrong. It is the single most common setup hiccup, and now you know its one line by sight.

Watch the quote marksIf you copy code off a web page, the straight quotes around ‘Hello, world!’ can turn into curly quotes that look almost identical. Python rejects them with a SyntaxError. If a line that should work refuses to run, retype the quotes yourself. This bites nearly every beginner once, and it is invisible until you know to look.

The project starts here

Across this series you will build one real program a little at a time: a command line expense tracker that records what you spend. By the end it is a finished piece you can show in an interview. It starts now, with the smallest possible version, so you can prove your setup runs a file of your own.

Make a second file next to hello.py called expenses.py with one line in it:

expenses.py
print('My Expense Tracker')
output
My Expense Tracker

Run it the same way you ran hello.py. One printed title line is not much yet, but this file is the seed of everything. In Part 3 it starts holding an amount and a category. Keep the file; do not delete it between parts.

Why this matters in your first jobOn day one at a real job, nobody watches you write clever code. They watch whether you can set up a working environment and run something without hand holding. "Clone the repo, install the dependencies, get it running locally" is a genuine first task at most companies. The install, the PATH check, the cd into the right folder: this is that exact skill in miniature. Getting comfortable here pays off the first week you are hired.

When install goes sideways

Most setup problems are one of a handful of things. Here they are with the cause and the fix, so you can match a message to an answer instead of guessing.

What you seeWhat it meansThe fix
‘python’ is not recognized (Windows)Python is not on your PATHRe-run installer, tick Add to PATH, or use py
command not found (macOS, Linux)Wrong command nameUse python3, not python
can’t open file ‘hello.py’Wrong foldercd into the folder, then run again
SyntaxError near a quoteCurly quotes from copyingRetype the straight quote marks

Table 2. The four setup messages nearly everyone meets, and what to do.

Real interview question"What is the difference between running code in the Python shell and running a script?" A clean answer: the interactive shell, or REPL, runs one line at a time and shows the result immediately, which is good for quick experiments but keeps nothing after you close it. A script is code saved in a .py file that runs as a whole and can be saved, shared, and rerun. Junior candidates who can say this plainly signal that they have actually used the tools, not just read about them.
Try it yourselfChange hello.py so it prints two lines: your name on the first line, and the word ready on the second. Run it. Expected output:
expected output
Asha
ready
Show solution
hello.py
print('Asha')
print('ready')

Two separate print lines make two output lines. Use your own name in place of Asha. Each print ends its line for you.

Questions that come up right after installing

Do I need to pay for anything, or install an IDE? No. Python is free, and the official installer already includes a simple editor called IDLE. A text editor and a terminal are enough for this whole series. Many people add VS Code later because it is pleasant, but it is optional.

Windows offers Python in the Microsoft Store. Should I use that instead? The python.org installer is the more predictable choice for learning, because paths and permissions behave the way tutorials assume. The Store version works, but if a command acts strangely, the official installer removes one variable.

I have Python 3.11 already. Do I need to upgrade to 3.14? No. Anything from 3.11 onward runs everything in this series. Upgrade when it is convenient, not as a blocker to starting.

Why does my Mac say python3 but the tutorial says python? On macOS and Linux the command is python3. On Windows it is usually python or py. Same interpreter, different name by system. Use whichever your machine recognizes.

My terminal shows a different version number than yours. Is that a problem? No. Patch numbers like 3.14.6 change often. As long as it starts with 3, you are set.

You can nowYou can now install Python on your own machine, confirm it from a terminal, run code both in the interactive prompt and from a saved .py file, and read the four setup errors that stop most beginners. Your expense tracker exists as a real file. In Part 3 it starts remembering numbers.
Python for Beginners · Part 2 of 20
« Previous: Part 1  |  Complete Guide  |  Next: Part 3

About The Author


Discover more from Journal of Intelligent Infrastructure – By Dr Pranay Jha

Subscribe to get the latest posts sent to your email.

Leave a Reply

Your email address will not be published. Required fields are marked *

Architect’s Toolkit

About the Author

Dr. Pranay Jha is a Cloud and AI Consultant with 18+ years of experience in hybrid cloud, virtualization, and enterprise infrastructure transformation. He specializes in VMware technologies, multi-cloud strategy, and Generative AI solutions. He holds a PhD in Computer Applications with research focused on Cloud and AI, has published multiple research papers, and has been a VMware vExpert since 2016 and a VMUG Community Leader.

Discover more from Journal of Intelligent Infrastructure - By Dr Pranay Jha

Subscribe now to keep reading and get access to the full archive.

Continue reading