Lesson 1 - Python Environment Setup
Learning Objective
Install VS Code and Python on your computer, configure them to work together, confirm the installation works from the terminal, and run your first Python script.
Introduction
Before writing any code, you need two things:
- A code editor where you’ll write your programs.
- The Python interpreter that executes your code.
In this course, we’ll use Visual Studio Code (VS Code) as our editor and Python 3 as our programming language. By the end of this lesson, you’ll have a complete development environment ready to write and run Python programs.
Step 1: Install VS Code
VS Code is one of the most popular editors for Python development. It provides syntax highlighting, code completion, debugging tools, and an integrated terminal.
Install the Python Extension
After installing VS Code:
- Open VS Code.
- Navigate to the Extensions panel (
Ctrl+Shift+Xon Windows/Linux,Cmd+Shift+Xon macOS). - Search for Python.
- Install the Python extension published by Microsoft.
This extension provides:
- Python language support
- IntelliSense (code completion)
- Debugging tools
- Jupyter Notebook support
- Virtual environment detection
Step 2: Install Python
Download the latest stable version of Python from:
Installation Notes by Operating System
Windows
During installation, check the box “Add Python to PATH” before clicking Install. This is the most commonly missed installation step.
Step 3: Verify Python Installation
Open a terminal:
- Windows: Command Prompt or PowerShell
- macOS: Terminal
- Linux: Terminal
Run:
python --versionOr on some systems:
python3 --versionYou should see output similar to:
Python 3.12.3Your exact version number may differ.
Step 4: Configure VS Code to Use Python
Once Python is installed:
- Open VS Code.
- Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS).
- Search for:
Python: Select Interpreter- Choose the Python version you just installed.
VS Code should now recognize Python automatically.
If Python does not appear in the interpreter list, restart VS Code and try again.
Step 5: Create Your First Python Program
Create a file named:
hello_python.pyAdd the following code:
# hello_python.py
import sys
print("Hello, Python!")
print(
f"You're running Python "
f"{sys.version_info.major}."
f"{sys.version_info.minor}."
f"{sys.version_info.micro}"
)Step 6: Run the Program
Open the VS Code integrated terminal:
Terminal → New TerminalNavigate to the folder containing hello_python.py and run:
python hello_python.pyOr, on some systems:
python3 hello_python.pyExpected Output
Click to see expected output
Hello, Python!
You're running Python 3.12.3Your exact version number will differ depending on the Python version you installed.
🔧 Under the Hood
What does “running” a Python file actually do?
Python is an interpreted language, not a compiled one. Languages like C or Rust are translated into machine code ahead of time by a compiler, producing a standalone executable.
Python instead reads your .py file one statement at a time and executes each statement immediately using the Python interpreter (python or python3) as the execution engine.
This trade-off is why Python programs tend to run slower than compiled languages, but it’s also why Python feels so fast to write and test. There is no separate compile step between writing code and running it.
Student Challenge
Reflection Question
You ran the same
hello_python.pyfile using the interpreter, not a compiler. What advantages might this give you while you’re still learning and making mistakes, compared to a language that requires a compile step before every run?
By the end of this lesson, you should have VS Code installed, Python configured, a working interpreter selected inside VS Code, and your first Python program successfully running.