Lesson 2: Installing Python
⏱️ Estimated time: 15-20 minutes
📚 Learning Objectives
By the end of this lesson, you will be able to:
- Download and install Python 3 on your operating system
- Verify that Python is correctly installed
- Understand what PATH is and why it matters
- Open a terminal or command prompt on your computer
- Choose a text editor or IDE for writing Python code
Before You Begin
To write and run Python programs, you need two things installed on your computer:
- Python itself — the interpreter that understands and runs your code
- A text editor or IDE — a program where you write your code
IDE (Integrated Development Environment) is a software application that provides tools for writing, running, and debugging code all in one place. Think of it as a "workshop" for programmers, with everything you need at your fingertips.
Let's start by installing Python. The instructions vary depending on your operating system, so select yours below.
Installing Python 3
Installing Python on Windows
-
Go to python.org
Open your web browser and navigate tohttps://www.python.org/downloads/ -
Download the installer
Click the big yellow "Download Python 3.x.x" button. The website will detect your operating system automatically. -
Run the installer
Double-click the downloaded.exefile to start the installer. -
IMPORTANT: Check "Add Python to PATH"
At the bottom of the first installer screen, you will see a checkbox that says "Add python.exe to PATH". Check this box! This is the most common mistake beginners make. Without it, your computer won't know where to find Python. -
Click "Install Now"
The default installation settings are fine for beginners. Click "Install Now" and wait for the installation to complete. -
Click "Close"
Once you see "Setup was successful", click Close.
⚠️ Most Common Mistake
Forgetting to check "Add Python to PATH" means you'll get errors when trying to run Python from the command line. If you already installed without checking it, simply uninstall Python and reinstall it with the checkbox checked.
Installing Python on Mac
Mac computers come with an older version of Python pre-installed, but we need Python 3.
-
Go to python.org
Open Safari (or your preferred browser) and navigate tohttps://www.python.org/downloads/ -
Download the installer
Click the "Download Python 3.x.x" button. Download the macOS installer package. -
Run the installer
Open the downloaded.pkgfile and follow the installation prompts. Click "Continue" through the steps and "Agree" to the license. -
Complete installation
Click "Install" and enter your Mac password when prompted. Wait for the installation to finish. -
Verify the installation
Open Terminal (search for "Terminal" in Spotlight, or find it in Applications > Utilities) and type:python3 --version
💡 Mac Note
On Mac, you may need to type python3 instead of python because the older Python 2 may still be linked to the python command. Throughout this course, if python doesn't work on Mac, try python3 instead.
Installing Python on Linux
Most Linux distributions come with Python 3 pre-installed. Let's check first.
-
Open a terminal
PressCtrl + Alt + Tor search for "Terminal" in your applications menu. -
Check if Python 3 is installed
Type:python3 --version
If you see a version number (e.g., "Python 3.10.12"), you're already set! -
If not installed, install via package manager
Ubuntu/Debian:sudo apt update sudo apt install python3 python3-pip
Fedora:sudo dnf install python3 python3-pip
-
Verify the installation
python3 --version
Verifying Your Installation
After installing, let's make sure everything works. Open your terminal (Mac/Linux) or Command Prompt (Windows):
💻 Opening the Terminal / Command Prompt
- Windows: Press
Win + R, typecmd, press Enter. Or search "Command Prompt" in the Start menu. - Mac: Press
Cmd + Space, type "Terminal", press Enter. - Linux: Press
Ctrl + Alt + T.
Now type the following and press Enter:
python --version
If you see a version starting with 3 (like 3.10, 3.11, 3.12, etc.), you're all set! If you get an error on Mac or Linux, try python3 --version instead.
✍️ Try It Yourself!
Open your terminal right now and verify your Python installation. If it's not working, go back through the installation steps for your operating system.
Understanding PATH
PATH is an environment variable that tells your operating system where to look for programs. When you type python in the terminal, your computer searches the directories listed in PATH to find the Python program.
Think of PATH like a list of addresses your computer checks when you ask it to run a program. If Python's location isn't in this list, your computer won't be able to find it, even though it's installed.
🔎 Checking Your PATH (optional)
You can see where Python is installed by typing:
Windows:
where python
Mac/Linux:
which python3
This shows the exact location of the Python executable on your system.
Choosing a Text Editor or IDE
You need a place to write your Python code. While you could use basic Notepad, a proper code editor makes programming much easier with features like syntax highlighting, auto-completion, and error detection.
Recommended Options for Beginners
⭐ VS Code (Visual Studio Code)
Best overall choice. Free, lightweight, and incredibly popular. Install the Python extension for an excellent experience.
Download from code.visualstudio.com
📡 IDLE
Comes with Python! No extra installation needed. Simple and straightforward. Good for absolute beginners who want to start immediately.
Already installed with Python
🚀 Thonny
Designed for beginners. Built-in Python, simple interface, and a great debugger that shows you what's happening step by step.
Download from thonny.org
⚡ Sublime Text
Fast and clean. A sleek editor that's fast to open and easy to use. Free evaluation with occasional purchase reminders.
Download from sublimetext.com
Our Recommendation
For this course, we recommend starting with IDLE (since it comes with Python) and eventually moving to VS Code as you get more comfortable. Both are free, and you can switch between them anytime.
Opening IDLE
IDLE (Integrated Development and Learning Environment) is Python's built-in editor. Here's how to open it:
- Windows: Search for "IDLE" in the Start menu. You should see "IDLE (Python 3.x)".
- Mac: Open Finder, go to Applications, find the Python 3.x folder, and double-click IDLE.
- Linux: Type
idle3in the terminal, or search your applications menu.
When IDLE opens, you'll see the Python Shell—an interactive window with a >>> prompt. This is the Python interpreter, which we'll explore in detail in Lesson 4.
✍️ Try It Yourself!
Open IDLE right now. You should see something like:
Python 3.12.1 (tags/v3.12.1:2305ca5, Dec 7 2023) [GCC 13.2.0] on linux Type "help", "copyright", "credits" or "license()" for more information. >>>
Type print("I installed Python!") at the >>> prompt and press Enter. If you see your message, congratulations—everything is working!
✅ Check Your Understanding
1. When installing Python on Windows, what critical checkbox must you check?
2. What command do you type in the terminal to check if Python is installed?
python --version (or python3 --version on Mac/Linux). If Python is installed correctly, it will display the version number.
3. What is PATH and why does it matter for Python?
python.
4. What is IDLE and how do you open it?
🎯 Key Takeaways
- Download Python from python.org/downloads—always get Python 3
- On Windows, always check "Add Python to PATH" during installation
- Verify your installation with
python --versionin the terminal - PATH is the system's list of directories to search for programs
- IDLE comes with Python and is a great starter editor
- VS Code is recommended as you progress
Ready for More?
➡️ Next Lesson
In Lesson 3, you'll write your first Python program—the famous "Hello, World!" and beyond!
Start Lesson 3📊 Module Progress
You've completed Lesson 2! Your development environment is set up and ready to go.