Skip to Content
BonicBot A2DevelopmentPython ProgrammingLesson 1 - Python Environment Setup

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:

  1. A code editor where you’ll write your programs.
  2. 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:

  1. Open VS Code.
  2. Navigate to the Extensions panel (Ctrl+Shift+X on Windows/Linux, Cmd+Shift+X on macOS).
  3. Search for Python.
  4. 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

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 --version

Or on some systems:

python3 --version

You should see output similar to:

Python 3.12.3

Your exact version number may differ.


Step 4: Configure VS Code to Use Python

Once Python is installed:

  1. Open VS Code.
  2. Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS).
  3. Search for:
Python: Select Interpreter
  1. 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.py

Add 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 Terminal

Navigate to the folder containing hello_python.py and run:

python hello_python.py

Or, on some systems:

python3 hello_python.py

Expected Output

Click to see expected output

Hello, Python! You're running Python 3.12.3

Your 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.py file 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.

Last updated on