1. Install Python

Install Python & VS Code; Run Your First Script — Step-by-Step Guide

This practical guide walks you through installing Python and Visual Studio Code (VS Code) on Windows, macOS, or Linux, then writing, running, and debugging your first Python script. It also covers virtual environments, package management (pip), and common troubleshooting tips.

What You Will Need

  • An internet connection
  • Administrator access on your machine (recommended for installation)
  • About 15–30 minutes

Part 1 — Install Python  Windows

  1. Go to https://www.python.org/downloads/.
  2. Download the latest Python 3.x Windows installer.
  3. Run the installer. IMPORTANT: tick “Add python.exe to PATH”.
  4. Choose “Install Now” (recommended).
  5. Open Command Prompt and verify:

python –version
python -m pip –version

macOS

  • Option A (recommended): Install via Homebrew.
  • Open Terminal and run:

brew install python
python3 –version
python3 -m pip –version

If you do not use Homebrew, download the macOS installer from https://www.python.org/downloads/ and follow on-screen steps. Use python3 in Terminal on macOS.

Linux (Ubuntu/Debian examples)

Python 3 usually ships with your distro. Update and verify:
sudo apt update
python3 –version
python3 -m pip –version || sudo apt install -y python3-pip
Create and Use a Virtual Environment (All OS)
Create a project folder, e.g., hello-python.
Create a virtual environment inside it:

python -m venv .venv   # use `python3` on macOS/Linux if needed

Activate the environment:

Windows (Command Prompt):   .\.venv\Scripts\activate
Windows (PowerShell):      .\.venv\Scripts\Activate.ps1
macOS/Linux (bash/zsh):    source .venv/bin/activate

Upgrade pip (recommended):

python -m pip install –upgrade pip

Part 2 — Install Visual Studio Code (VS Code)

  1. Download VS Code for your OS from https://code.visualstudio.com/Download.
  2. Install it with default options.
  3. Open VS Code and install the official “Python” extension by Microsoft.
  4. Open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P) and run “Python: Select Interpreter”. Choose the interpreter in your project’s .venv folder.

Part 3 — Your First Python Script  –> Run from the Terminal

  • Inside your project folder, create a file hello.py with the following code:

print(‘Hello, world!’)

name = input(‘What’s your name? ‘)
print(f’Nice to meet you, {name}!’)

  • Run the script:

python hello.py   # use python3 on macOS/Linux if needed

Run Inside VS Code

  1. Open the folder (File → Open Folder…) and select your project.
  2. Open hello.py.
  3. Make sure the selected interpreter is your .venv.
  4. Click the ▶ Run button or use the built-in terminal (View → Terminal) and run `python hello.py`.

Part 4 — Debugging in VS Code

  1. Open hello.py and set a breakpoint by clicking left of the line number.
  2. Press F5 (Run and Debug) and choose “Python File”.
  3. Use the Variables panel, Step Over (F10), Step Into (F11), and Continue (F5).

Part 5 — Installing and Using Packages (pip)

  • Ensure your virtual environment is activated.
  • Install a popular package, e.g., requests:

python -m pip install requests

Example: fetch a web page and print its HTTP status code:

import requests

resp = requests.get(‘https://httpbin.org/get’)
print(‘Status:’, resp.status_code)
print(‘JSON keys:’, list(resp.json().keys()))

Part 6 — Common Troubleshooting

  • Command not found: Use python3 instead of python on macOS/Linux; ensure PATH is set on Windows.
  • Pip not found: Try `python -m pip` (or `python3 -m pip`).
  • Activate venv: Make sure your shell is using the project’s .venv; see activation commands above.
  • VS Code uses wrong interpreter: Use “Python: Select Interpreter” and pick the .venv one.
  • PowerShell script execution policy (Activate.ps1): Run PowerShell as Administrator and execute
      `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned` (understand security implications first).

Appendix — Quick Commands Reference

Verify versions
python –version
python -m pip –version

# Create and activate virtual environment
python -m venv .venv
# Windows (CMD)
.\.venv\Scripts\activate
# Windows (PowerShell)
.\.venv\Scripts\Activate.ps1
# macOS/Linux
source .venv/bin/activate

# Upgrade pip
python -m pip install –upgrade pip

# Run a script
python hello.py

# Install packages
python -m pip install <package>

Scroll to Top
Tutorialsjet.com