Logo OnlineCBT
PYTHON Tutorial
PYTHON · LESSON 2

Install Python and Set Up VS Code

Install a modern Python version, verify it from the terminal, and create a clean workspace in Visual Studio Code.

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive
Updated: 25 Jul 2026

Lesson 2: Install Python and Set Up VS Code

1. Introduction to the Python Development Environment

Before writing Python code, you must establish a reliable development stack. A standard environment requires two main components:

  1. The Python Interpreter: The core engine that translates your Python code into machine-executable instructions.
  2. A Code Editor (IDE): Visual Studio Code (VS Code) is the industry standard tool for writing, debugging, and managing source files.
Key Concept: The code editor does not execute Python code by itself. It sends your code to the Python Interpreter installed on your system. Both components must be configured correctly to work together.

2. Step 1 — Installing Python Correctly

Windows Installation Instructions

  1. Visit the official portal: python.org/downloads/.
  2. Download the latest stable Windows installer (64-bit).
  3. Run the downloaded executable file.
CRITICAL STEP (Windows): On the installer interface, check the box that says "Add python.exe to PATH" before clicking "Install Now". Skipping this step prevents your Command Prompt or VS Code terminal from recognizing Python commands.

macOS Installation Instructions

macOS includes a minimal system Python environment, but you should install the official release for development work.

  • Option A (Direct Installer): Download and run the macOS 64-bit universal2 installer from python.org.
  • Option B (Homebrew Package Manager): Run brew install python in Terminal.

Linux (Ubuntu/Debian) Installation Instructions

Linux distributions include Python 3 by default. Update and verify using your terminal:

sudo apt update
sudo apt install python3 python3-pip python3-venv
    

3. Step 2 — Verifying the Installation via CLI

Confirm that your operating system detects the Python interpreter and the package manager (pip).

Open Terminal (macOS/Linux) or Command Prompt / PowerShell (Windows) and enter:

python --version

(Note: On macOS/Linux systems, use python3 --version)

Verify pip (Python's Package Installer):

pip --version
Expected Output: The system should return a version tag, such as Python 3.12.x (or higher). If you see "command not found" or "'python' is not recognized", the executable was not added to your system's PATH.

4. Step 3 — Installing and Configuring VS Code

Downloading Visual Studio Code

  1. Navigate to code.visualstudio.com.
  2. Download the appropriate version for your OS (Windows, macOS, or Linux).
  3. Complete the installation wizard (keep default settings enabled).

Installing Essential Extensions

VS Code requires extension plugins to enable complete Python tooling support:

  1. Open VS Code.
  2. Click the Extensions icon on the left sidebar (or press Ctrl + Shift + X / Cmd + Shift + X).
  3. Search for Python (published officially by Microsoft).
  4. Click Install. This automatically installs the Python, Pylance, and Python Debugger extensions.

5. Step 4 — Selecting the Python Interpreter in VS Code

To run Python files within VS Code, link the editor to your installed Python interpreter path.

  1. Open the Command Palette: Press Ctrl + Shift + P (Windows) or Cmd + Shift + P (macOS).
  2. Type: Python: Select Interpreter and press Enter.
  3. Select your installed Python version from the list (e.g., Python 3.x.x ('recommended')).
Status Bar Check: Look at the bottom-right corner of VS Code. You should see the selected Python interpreter version listed.

6. Essential VS Code Keyboard Shortcuts

These shortcuts speed up daily workflow in VS Code:

  • Open Command Palette
  • Ctrl + Shift + P
  • Cmd + Shift + P
  • Toggle Integrated Terminal
  • Ctrl + ` (Backtick)
  • Cmd + ` (Backtick)
  • Run Current File
  • F5 or Play Button
  • F5 or Play Button
  • Open Extensions View
  • Ctrl + Shift + X
  • Cmd + Shift + X
Action / Feature Windows / Linux Shortcut macOS Shortcut

7. Troubleshooting System PATH Issues

If your terminal throws a PATH error despite completing installation, resolve it with these steps:

Manual PATH Configuration (Windows)

  1. Press Win + S, search for Environment Variables, and open "Edit the system environment variables".
  2. Click Environment Variables... at the bottom right.
  3. Under User variables, select Path and click Edit.
  4. Add the installation path (default location):
    C:\Users\\AppData\Local\Programs\Python\Python3xx\
  5. Add the Scripts path:
    C:\Users\\AppData\Local\Programs\Python\Python3xx\Scripts\
  6. Click OK and restart VS Code or Command Prompt.

8. Frequently Asked Interview Questions with Answers

Q1: What is the system PATH environment variable, and why is it critical for Python?
Answer: PATH is a system variable that lists executable directories for the operating system. Adding Python to PATH allows you to invoke the python command from any terminal directory, without providing its absolute path (e.g., C:\Python312\python.exe).
Q2: What is the difference between a Code Editor (VS Code) and an IDE (PyCharm)?
Answer: VS Code is a modular code editor that uses lightweight extensions for customized language support. PyCharm is a dedicated Integrated Development Environment (IDE) with built-in database management, native profiling, and full web toolkits out of the box.
Q3: What is the function of the `pip` command in Python ecosystem management?
Answer: pip stands for "Pip Installs Packages". It is Python's standard package manager used to download, install, update, and manage third-party libraries hosted on the Python Package Index (PyPI).
Q4: How do you verify which Python executable VS Code is currently executing?
Answer: Check the interpreter indicator on the status bar (bottom right), or open the integrated terminal and execute: import sys; print(sys.executable) inside Python.
Q5: What is Pylance in VS Code?
Answer: Pylance is the language server engine for Python in VS Code. It provides type checking, auto-imports, syntax highlighting, and code completion.

9. Homework & Practical Setup Checklist

Task 1: Verification Checklist

Complete these tasks and record your results:

  1. Run python --version or python3 --version in your terminal and note the version number.
  2. Run pip --version to verify package installer accessibility.
  3. Launch VS Code, open the integrated terminal (Ctrl + `), and confirm your terminal detects Python.

Task 2: Extension Setup

Ensure the following extension pack is active in your editor:

  • Python Extension (Publisher: Microsoft)
  • Pylance (Publisher: Microsoft)

Task 3: Interpreter Mapping

Open the Command Palette (Ctrl/Cmd + Shift + P), run Python: Select Interpreter, and confirm your target path is linked.


10. File & Directory Setup Guide

Workspace Standard:

Create a structured course folder on your computer:

  • Main Directory: python_mastery_course
  • Lesson Directory: lesson_02

Directory Architecture Tree:

python_mastery_course/
│
├── lesson_01/
│   └── homework_submission.md
│
└── lesson_02/
    └── environment_setup_verification.txt
        

11. What We Will Learn Next

Next Up: Lesson 3 — Your First Python Program and the REPL

With your environment and editor configured, you are ready to write and run Python scripts.

In the next lesson, we will cover:

  • Understanding the REPL (Read-Eval-Print Loop) interactive shell.
  • Creating and saving your first source script (hello.py) in VS Code.
  • Working with the print() function, string parameters, and line control.
  • Understanding basic syntax rules and avoiding early syntax errors.

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
Address Contact

+91 7877547686

E-mail

onlinecbtportal@gmail.com

Helpline Number

+91 7877547686


Click To Download
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat