Installing Python
Get Python running on your computer and write your very first .py file — no experience needed.
Before you can write Python programs, you need Python itself installed on your computer. Think of it like installing a music player before you can listen to songs — the code is the song, and Python is the player that makes it run.
This lesson walks you through the whole setup: downloading Python, picking a code editor, and running your first file. By the end, you'll have a working Python environment ready to go.
See it in action
— step through the idea, then dive into the details below.Python: Your New Superpower
Before you can write Python programs, you need Python installed on your computer. Think of it like a music player — the code is the song, Python is the player that makes it run.
#Downloading Python
Python is free and available for Windows, macOS, and Linux. The official home is python.org. Head to python.org/downloads and click the big download button — it will detect your operating system automatically.
Always grab the latest stable version (the one that doesn't say "pre-release" or "alpha"). At the time of writing that's Python 3.12 or newer.
Windows users: check "Add Python to PATH"
During installation on Windows you will see a checkbox at the very bottom of the first screen that says "Add Python to PATH". Make sure you tick it before clicking Install.
If you skip this, your terminal won't know where to find Python and commands like python --version will fail with a confusing error. If you already installed without it, just uninstall and reinstall — it only takes a minute.
#Mac and Linux
On macOS, an old Python 2 is sometimes pre-installed, but you want Python 3. After installing from python.org (or using a tool like Homebrew), always use the command python3 instead of python in your terminal. This avoids accidentally calling the old version.
On Linux, Python 3 is often already installed. Open a terminal and try python3 --version to check.
#Verifying Your Installation
Once installed, open a terminal (called "Command Prompt" or "PowerShell" on Windows, "Terminal" on macOS/Linux) and type one of the commands below. If Python is installed correctly, it prints its version number.
# On Windows — type this in Command Prompt or PowerShell:
python --version
# On macOS / Linux — type this in Terminal:
python3 --versionNo version number? Try the other command
Some systems register Python as python, others as python3. If one doesn't work, try the other. Throughout this course we'll use python3 in examples, but substitute python if that's what works on your machine.
#Choosing a Code Editor
A code editor is a program designed for writing code. You could use Notepad, but a proper editor gives you superpowers: colored syntax, error hints, auto-complete, and a built-in terminal.
Here are two great options to start with:
- VS Code (Visual Studio Code) — free, beginner-friendly, and wildly popular. Download at code.visualstudio.com. Install the "Python" extension (by Microsoft) once it's open.
- IDLE — ships with Python automatically. It's simpler and great for tiny experiments, though VS Code is better for real projects.
Editor vs. Python — what's the difference?
Think of Python as a car engine and your code editor as the dashboard and steering wheel. The engine does the actual work; the dashboard just gives you a nice way to control it. You could theoretically hot-wire the car (write code in Notepad), but the dashboard makes everything much nicer.
#Creating and Running Your First File
Python programs are saved in plain text files with the .py extension. Here's how to create and run one:
- Open your editor and create a new file called
hello.py. - Type a line of Python code inside it.
- Save the file.
- Open your terminal, navigate to the folder where you saved the file, and run it.
# hello.py
print("Hello, world!")# In your terminal, navigate to the file's folder, then run:
python3 hello.py"No such file or directory" error
This means your terminal is looking in the wrong folder. Use cd ("change directory") to navigate to where your file is saved.
For example: cd Desktop or cd Documents/my-python-projects.
Tip: In VS Code you can open a terminal directly inside the editor — it automatically starts in the right folder.
#pip Comes Free
Python comes bundled with a tool called pip — the Python package installer. It lets you download free libraries written by other developers so you don't have to build everything from scratch. You don't need to install pip separately; it's already there. You'll use it in later lessons when your programs need extra features.
# Check that pip is available:
pip --version
# or on Mac/Linux:
pip3 --versionYou installed Python on Windows and now `python --version` gives an error like "'python' is not recognized". What is the most likely cause?
Key takeaways
- Download Python for free from python.org — always choose a Python 3 version.
- On Windows, tick "Add Python to PATH" during installation or commands won't work.
- Verify your install by running `python --version` or `python3 --version` in a terminal.
- VS Code is the recommended editor — free, powerful, and beginner-friendly.
- Run any Python file with `python3 filename.py` in your terminal; pip comes bundled automatically.
What does this code print?
print("Hello, world!")This code has a bug. What is wrong?
Print("Hello, world!")Complete the terminal command to run a Python file called hello.py on macOS or Linux.
hello.pyPut these lines in the right order to create and run a simple Python program.
# Step 2: Type your code inside the file
# Step 3: Save the file, then run it from the terminal
print("Hello, world!")python3 hello.py
# Step 1: Create a new file called hello.py in your editor
Create a file called about_me.py. Inside it, use print() to display three lines: your name, your favorite color, and why you want to learn Python. Then run the file from your terminal and confirm all three lines appear.
Try it live — edit the code and hit Run to execute real Python: