Installing Python and your first script
By the end of this series you'll have a command-line expense tracker that stores real data on disk and runs like any other terminal tool. This first part gets Python running and puts a file on disk you can execute — nothing else, so that any error you hit later comes from your code rather than your setup.
Check what you already have
macOS and most Linux distributions ship with Python. Windows usually doesn't. Check before installing anything:
python3 --versionOn Windows, try python --version instead. If you get 3.10 or newer, you're set. Anything older — or a command not found — means installing from python.org/downloads, where the installer handles the details for your platform.
On the Windows installer's first screen, tick Add python.exe to PATH before clicking Install. Without it, python won't be recognized in a new terminal and you'll be editing environment variables by hand later.
Create the project
Make a folder for the tracker and move into it:
mkdir expense-tracker
cd expense-trackerEvery command from here on assumes you're inside this folder.
Create a virtual environment
A virtual environment is a private copy of Python for one project. Packages you install go into it instead of your system Python, so two projects can use different versions of the same library without a conflict:
python3 -m venv .venvThat creates a .venv folder. Creating it isn't enough — you have to activate it in each new terminal session:
source .venv/bin/activateOn Windows PowerShell, the activate script lives elsewhere:
.venv\Scripts\Activate.ps1Your prompt now starts with (.venv). That prefix is the whole point: it tells you which Python will run when you type python. When it's missing, you're back on the system one.
Your first script
Create a file named tracker.py with two lines:
print("Expense tracker")
print("No expenses yet.")Run it:
python tracker.pyBoth lines appear in the terminal. print() writes its argument to standard output and adds a newline — it's how a script talks back to you, and it's the tool you'll use most while learning, because it shows you what a value actually contains instead of what you assume it contains.
If you see python: command not found while (.venv) is in your prompt, the environment was created by a different Python than the one on your PATH. Delete the .venv folder, re-run the venv command with the exact interpreter that answered --version above, and activate it again.
Why a .py file instead of the REPL
Typing python with no arguments opens an interactive prompt where you can run one line at a time. It's useful for checking what a function does, but everything vanishes when you close it. A .py file is a program you can re-run, edit, and eventually hand to someone else — which is what you want for anything you'll use more than once.
Next up: reading input from whoever is running the script, and the type conversion that trips up nearly everyone the first time.