← Python for Treasury Work

Lesson 0 · Beginner · 20 min

Getting started: install Python and run your first script

Install Python on Windows or Mac, open the command line, and run a script, with fixes for the usual first errors.

✓ Last checked: November 2026 · code run, output real, facts checked

history of Pythoninstalling PythonCommand PromptTerminalpip

In this lesson

  • Where Python came from and why its libraries make it so powerful
  • Install Python 3 the right way on Windows or Mac
  • Open Command Prompt or Terminal and move into a folder
  • Run a Python script and read what it prints
  • Install extra libraries with pip
  • Fix the errors that almost everyone meets on day one

Every lesson in this series is a small Python script that you run on your own computer. This lesson sets that up. It takes about twenty minutes, and you only do it once.

Why Python? A short history

Before we install it, it helps to know where Python came from. It did not start in a big company. It started as one programmer's holiday project, and it grew into one of the most widely used programming languages in the world.

1989 Guido van Rossum, a Dutch programmer, began writing Python over the Christmas holidays as a hobby. He wanted a language that was easy to read and quick to write. He named it after the British comedy show Monty Python's Flying Circus, not after the snake.

1991 The first version was shared freely with the public. From the start, anyone could use it, read its code and help improve it, at no cost.

2000 Python 2 came out and the language spread to schools, offices and websites.

2008 Python 3 cleaned up old design mistakes, such as how text in other languages is handled. Python 2 was retired in 2020, so today everyone uses Python 3, and so do these lessons.

Today Python sits at or near the top of the rankings of the most used programming languages. It runs inside banks, government agencies, universities, scientific labs and websites such as Instagram. It is also the main language for data analysis and artificial intelligence.

Where its power comes from: the libraries

Python itself is simple. Its real strength is the huge collection of ready-made code, called libraries, that people around the world have written and shared for free. Python's public library index, PyPI, holds more than half a million of them. Instead of building everything from scratch, you bring in a library with one line and use what experts have already tested.

  • Built in, with nothing to install: csv reads spreadsheet exports, decimal keeps peso amounts exact to the centavo, datetime counts days and months for penalties, and sqlite3 stores records in a small database. These come with Python; people call it "batteries included".
  • pandas works with tables of thousands of rows the way Excel does, but in seconds and without mistakes from dragging formulas. It was first written by Wes McKinney in 2008 at a financial firm, to analyse money data. That makes it a natural fit for treasury work.
  • NumPy does fast calculations on large sets of numbers. pandas and many other libraries are built on top of it.
  • openpyxl reads and writes real Excel files, so a script can fill in a report template for you.
  • Flask turns Python code into a website or web system. This very site is written in Python, and ALTOS is built in Python too.

This is why one office worker with a laptop can do with a short script what used to need a team and expensive software. Collections can be added up, receipt series checked and penalties computed in seconds, the same way every time.

Note: Python's guiding rules are built into it. After you install it, type py (Windows) or python3 (Mac) to open Python, then type import this and press Enter. You will see "The Zen of Python", which includes the line "Readability counts." Type exit() to leave.

1. Install Python

  1. Go to python.org and open Downloads.
  2. Windows: download the Python install manager, double-click it and click Install. (You can also get the same "Python Install Manager" free from the Microsoft Store.) Then press the Windows key, type cmd, open Command Prompt, and type the command shown below the steps. It downloads the latest Python 3 for you. If it asks any setup questions, pressing Enter to accept the suggested answer is fine.
  3. Mac: download the latest Python 3 macOS installer, open the downloaded .pkg file and follow the steps.
Command Prompt / Terminal
py install default      (Windows only)

Note: On Windows you may also see the older installer (.exe) listed. It still works until Python 3.16; if you use it, tick "Add python.exe to PATH" on its very first screen before clicking Install Now.

2. Open the command line

Python scripts are usually run by typing a short command. On Windows, press the Windows key, type cmd and open Command Prompt. On a Mac, press Cmd + Space, type Terminal and press Enter. Check that Python is there by typing the command below and pressing Enter. It should answer with a version number such as Python 3.15.2.

Command Prompt / Terminal
py --version          (Windows)
python3 --version     (Mac)

3. Make a folder and save the script

Make a folder for the lessons, for example python-lessons in your Documents. Open Notepad (Windows) or TextEdit (Mac, then choose Format, Make Plain Text), paste the code below, and save it in that folder as hello.py. You can also click Download on the code box. A code editor such as Visual Studio Code, which is free, makes this easier and colours the code like this page does.

hello.pyDownload
"""Your first Python script: a quick check that Python is installed and working."""

office = "Municipal Treasurer's Office"
receipts_today = 3
amounts = [1250.75, 4500.00, 105.00]

print("Hello from the", office)
print("Receipts today:", receipts_today)
print("First amount:", amounts[0])
print("Python can do arithmetic:", 2 + 3 * 4)

4. Run it

In Command Prompt or Terminal, move into the folder with cd (change directory), then run the script:

Command Prompt / Terminal
cd Documents\python-lessons      (Windows)
py hello.py

cd Documents/python-lessons       (Mac)
python3 hello.py

You should see exactly this:

Output of hello.py
Hello from the Municipal Treasurer's Office
Receipts today: 3
First amount: 1250.75
Python can do arithmetic: 14

Each print line in the code produced one line of output. Notice that 2 + 3 * 4 gives 14, not 20: Python multiplies before it adds, just like a calculator in scientific mode.

5. Install extra libraries with pip

Python comes with many modules built in. Others, such as pandas for Lesson 4, are installed once with pip:

Command Prompt / Terminal
py -m pip install pandas openpyxl          (Windows)
python3 -m pip install pandas openpyxl     (Mac)

When something goes wrong

'python' is not recognized On Windows, close Command Prompt, open a new one and try again, or use py instead of python. If neither works, press the Windows key, type Manage app execution aliases, open it and make sure the Python entries are switched on. The same fix applies if typing python opens the Microsoft Store. If you used the older .exe installer, run it again, choose Modify, and tick Add Python to environment variables.

No such file or directory Command Prompt is looking in a different folder. Use cd to move into the folder where you saved the file, and type dir (Windows) or ls (Mac) to see the files there.

SyntaxError Something in the code was typed differently, often a missing quote, bracket or colon. Python shows the line number; compare that line with the lesson.

IndentationError Python uses the spaces at the start of a line to group code. Lines inside a for or with block must be indented by the same amount, usually four spaces.

ModuleNotFoundError: No module named 'pandas' The library is not installed yet. Run the pip command above.

Note: Copying the code from this page with the Copy button is the safest way to start. Once a script runs, change one thing at a time and run it again to see what happens.