Installing Python Locally (VS Code + venv)

You don't need this to start the course โ€” Google Colab already covers you. This is for when you're ready to code on your own machine, in your own editor.

Overview

This topic walks through installing Python on your own computer and setting up Visual Studio Code as your editor, plus creating an isolated virtual environment (venv) per project. It's a natural next step once you're comfortable with the basics in Google Colab and want a proper local setup for bigger projects.

๐Ÿ“Œ This topic is optional. Google Colab is enough to follow the rest of this course. Come back here whenever you want to move off the browser and onto your own machine.

Key Concepts

Step 1 โ€” Install Python

  1. Download the installer Go to python.org/downloads and download the latest stable version for your OS (Windows, macOS, or Linux).
  2. Run the installer (Windows) On the first setup screen, check the box "Add python.exe to PATH" before clicking Install โ€” this is the most commonly missed step and it's why python sometimes "isn't recognized" in the terminal afterward.
  3. macOS / Linux macOS and most Linux distributions already ship with a Python 3 install accessible as python3. You can install a newer version via a package manager instead of python.org if you prefer:
    # macOS (Homebrew)
    brew install python
    
    # Ubuntu / Debian
    sudo apt update
    sudo apt install python3 python3-pip python3-venv
    
    # Fedora
    sudo dnf install python3 python3-pip
    
    # Arch
    sudo pacman -S python python-pip
  4. Verify the install Open a terminal (Command Prompt / PowerShell / Terminal) and run:
    python --version
    # or, on some systems:
    python3 --version
    You should see something like Python 3.12.4.

Step 2 โ€” Install VS Code

  1. Download VS Code Go to code.visualstudio.com and download the installer for your OS, then install it like any other application.
  2. Install the Python extension Open VS Code, click the Extensions icon in the sidebar (or press Ctrl/Cmd + Shift + X), search for "Python" (by Microsoft), and click Install. This adds syntax highlighting, IntelliSense, debugging, and interpreter selection.
  3. Open your project folder Use File โ†’ Open Folder to open the folder where you'll keep your Python files โ€” VS Code works best when you open a folder rather than individual files.

Step 3 โ€” Create a Virtual Environment (venv)

A virtual environment keeps each project's installed packages separate, so different projects never conflict with each other's dependencies.

๐Ÿง Linux note: Most distros ship python3, not a plain python command โ€” use python3/pip3 below unless you've specifically aliased python. On Debian/Ubuntu, the venv module often isn't installed by default and creating one will fail with ensurepip is not available until you install it:
# Debian / Ubuntu only โ€” install venv support first
sudo apt update
sudo apt install python3-venv python3-pip
# Inside your project folder, create the environment
# Linux / macOS
python3 -m venv venv

# Windows
python -m venv venv

# Activate it โ€” Linux / macOS
source venv/bin/activate

# Activate it โ€” Windows (Command Prompt)
venv\Scripts\activate

# Activate it โ€” Windows (PowerShell)
venv\Scripts\Activate.ps1

Once active, your terminal prompt will show (venv) at the start of the line โ€” that's your confirmation it worked. Once the venv is active, python and pip inside it both point to the venv's own Python 3, even on Linux โ€” so you only need python3/pip3 for the one-time setup commands outside the venv.

๐Ÿ’ก Tip: The folder name venv is just a convention โ€” you can name it anything, but venv or .venv are the most common choices and are usually already ignored by default .gitignore templates.

Selecting the venv interpreter in VS Code

Once your virtual environment is created, tell VS Code to use it:

  1. Press Ctrl/Cmd + Shift + P to open the command palette.
  2. Type "Python: Select Interpreter" and select it.
  3. Choose the interpreter path that includes your venv folder (usually listed at the top as recommended).

Step 4 โ€” Install Packages with pip

With your virtual environment active, pip (not pip3) already points to the venv's own pip on every OS, including Linux:

pip install requests
pip install numpy pandas

To save your project's dependencies so others (or future-you) can recreate the same environment:

# Save current packages to a file
pip freeze > requirements.txt

# Recreate the environment elsewhere from that file
pip install -r requirements.txt

Step 5 โ€” Run Your First Local Script

Create a file named hello.py in your project folder:

print("Hello from my local Python setup!")

Run it from the VS Code terminal (with your venv active โ€” python works here on Linux too, since it now resolves to the venv's interpreter):

python hello.py
Hello from my local Python setup!

You can also click the โ–ถ "Run Python File" button in the top-right corner of VS Code while the file is open.

Things to Remember

Quick Revision

Install Python from python.org (checking "Add to PATH" on Windows), install VS Code plus its Python extension, then create a per-project virtual environment with python -m venv venv and activate it. Select that environment as your interpreter in VS Code, install packages with pip install, and run scripts with python filename.py. This local setup mirrors what Colab does for you automatically in the cloud โ€” useful once you're ready to work outside the browser, but not required to follow the rest of this course.