No history yet

Setting Up Python

Getting Python on Your Machine

Before you can write Python code, you need to install the Python interpreter. Think of the interpreter as a translator that understands the Python language and can execute your commands. Without it, your computer won't know what to do with a file ending in .py.

The best place to get Python is from the official source: python.org. Head to the downloads section and you'll see a big button to download the latest stable version. The website is smart enough to detect if you're on Windows, macOS, or Linux and will suggest the correct installer for you.

Lesson image

During installation, you'll see a series of prompts. On Windows, there's one very important checkbox you should tick: Add Python to PATH. Ticking this box makes it much easier to run Python from your computer's command line, a tool you'll use more as you advance. It tells your computer exactly where to find the Python interpreter, no matter which folder you're working in.

Your Coding Workspace

You can write code in any plain text editor, but it's much easier to use an Integrated Development Environment, or IDE. An IDE is software that combines a text editor with other helpful tools for programmers, like a way to run your code with a single click and tools to help you find mistakes.

IDE

noun

An Integrated Development Environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of at least a source code editor, build automation tools, and a debugger.

For beginners, we recommend an IDE called Thonny. It’s designed specifically for learning and teaching programming. The great thing about Thonny is that it comes with Python already built-in, so you don't have to worry about configuring anything. It has a clean, simple interface that keeps the focus on your code.

Lesson image

Your First Program

Once you have Thonny installed, open it up. You'll see a main window for writing code and a 'Shell' window below it. Let’s write a classic first program: one that simply prints "Hello, World!" to the screen. In the main editor window, type the following line of code:

print("Hello, World!")

This code uses the built-in print() function to display text. The text you want to display, which we call a string, goes inside the parentheses and must be wrapped in quotation marks.

Now, let's run it. You can either click the green 'Run' button in the toolbar or press the F5 key on your keyboard. Thonny will ask you to save the file first. Name it something like hello.py and save it to your desktop or a new project folder.

The .py extension is important. It tells your computer (and other programmers) that the file contains Python code.

After you save it, the code will run. You should see the text Hello, World! appear in the Shell window at the bottom. If you see that message, congratulations! Your Python environment is set up correctly, and you've just written and executed your first program.

Ready to check your understanding of setting up a development environment?

Quiz Questions 1/5

What is the primary role of the Python interpreter?

Quiz Questions 2/5

According to the lesson, what is a key advantage of using the Thonny IDE for beginners?