Lesson 2 of 25

Installing Python & Setup

What You Are Actually Installing

"Install Python" sounds like one thing, but the installer from python.org puts several separate pieces on your machine. Knowing their names saves you a lot of confusion later, because error messages refer to them by name and assume you know the difference.

The interpreter is the program that reads and runs your code — that is the python command. The standard library is a large collection of modules that ship with it, so math, json, random, datetime and roughly two hundred others are available with no download. pip is the package installer, used to fetch everything that is not in the standard library from the Python Package Index. IDLE is a small editor bundled along for convenience.

One more idea belongs here even though you will not use it today: the virtual environment. It is a private copy of the interpreter's package list for a single project, so installing a library for one project cannot break another. The last section of this lesson sets one up, and from then on this course assumes you are working inside one.

  • python — the interpreter; runs your .py files
  • The standard library — modules like math, json, csv, datetime, available immediately
  • pip — installs third-party packages such as requests or pandas
  • IDLE — a minimal editor that comes bundled; fine for a first hour, replaced quickly
  • On Windows only: py, a launcher that finds the right Python version for you

Installing It, Platform by Platform

Download from python.org/downloads and take the current stable 3.x release. Avoid the Microsoft Store version on Windows if you have a choice — it works, but it sandboxes file access in ways that produce confusing permission errors when you start writing files.

There is exactly one checkbox that matters on the Windows installer, and it is easy to miss because it sits at the bottom of the first screen: Add python.exe to PATH. Tick it. If you do not, Windows will not know where the interpreter lives and every command in this course will fail with "python is not recognized". The next section explains how to recover if you have already clicked through without ticking it.

  • Windows — run the installer, tick Add python.exe to PATH, then choose Install Now
  • macOS — use the official .pkg installer, or brew install python if you already have Homebrew
  • Linux (Ubuntu/Debian) — Python 3 is usually present; add the extras with sudo apt install python3-pip python3-venv
  • Low-spec laptop or no admin rights — use Google Colab in a browser; it runs Python 3 with the common data libraries already installed
Example
# Verify the install — open a NEW terminal window first,
# because PATH changes only apply to terminals opened afterwards.

python --version
# Python 3.12.4

python -m pip --version
# pip 24.0 from ...

# Windows also gives you the py launcher:
py --version
py -3.12 --version    # pick a specific version if several are installed

# macOS / Linux often need the 3 suffix:
python3 --version
python3 -m pip --version

"python is not recognized" — What PATH Means

This is the first error almost everyone hits, and it is not a Python error at all. PATH is a list of folders your operating system searches when you type a command. If the folder containing python.exe is not on that list, the shell reports that the command does not exist — even though the program is sitting on your disk.

The cheapest fix on Windows is to re-run the installer, choose Modify, and this time tick the PATH option. The second cheapest is to use the py launcher instead, which the installer registers separately and which usually works even when python does not. Editing PATH by hand in the system settings works too, but it is the fiddliest of the three and the easiest to get subtly wrong.

One habit prevents half of these problems: prefer python -m pip install X over a bare pip install X. The -m form says "run the pip module belonging to this interpreter". If you have two Pythons installed, a bare pip can quietly install a package into the one you are not using, and you then spend an hour staring at a ModuleNotFoundError for a package you are certain you installed.

Example
# The problem
C:\Users\you> python --version
'python' is not recognized as an internal or external command

# Fix 1 — re-run the installer, choose Modify, tick "Add python.exe to PATH"

# Fix 2 — use the launcher instead
C:\Users\you> py --version
Python 3.12.4

# Always install packages through the interpreter you are actually running
python -m pip install requests    # unambiguous
pip install requests             # may target a different Python
Notes
  • After changing PATH you must open a fresh terminal. An already-open window keeps the environment it started with, so the old error will keep appearing in it no matter what you fixed.

Choosing an Editor

Any plain text editor can write Python, but a proper editor pays for itself within a day. The features that matter are not the flashy ones: it is the red underline under a typo before you run anything, the pop-up that reminds you what arguments a function takes, and a debugger that lets you pause on a line and inspect every variable instead of scattering print() calls through your code.

For this course, VS Code with the official Python extension is the recommended setup — it is free, it runs acceptably on modest hardware, and it is the editor you are most likely to meet in an internship. PyCharm Community Edition is the stronger tool for large object-oriented projects but is noticeably heavier. Jupyter notebooks are a different shape of tool altogether: brilliant for data exploration, where you want to run one block, look at a chart, and adjust; poor for building an application, because the hidden execution order of cells makes bugs hard to reproduce.

  • VS Code + Python extension — the recommended default; light, free, industry-standard
  • PyCharm Community — richer refactoring and debugging, heavier on RAM
  • IDLE — already installed, adequate for your first few scripts
  • Jupyter / Google Colab — run-a-block-at-a-time notebooks; ideal for data work, not for applications
  • Any editor + terminal — entirely valid, and worth doing once so you understand what the IDE is doing for you
Notes
  • In VS Code, press Ctrl+Shift+P and run "Python: Select Interpreter" to choose which Python it uses. When you create a virtual environment, select it here — otherwise the editor will keep checking your code against the wrong set of installed packages.

Virtual Environments: Start the Habit Now

Installing packages straight into the system Python works right up until it does not. Project A needs one version of a library, project B needs a different one, and a single global install cannot satisfy both. Worse, on Linux the system Python is used by the operating system itself, and upgrading a package under it can break tools you did not know depended on it.

A virtual environment solves this by giving each project its own folder of installed packages. python -m venv .venv creates it, activating it changes which python and pip your terminal uses, and from then on every install is local to that project. Deleting the folder removes everything cleanly — there is nothing to uninstall.

You will know it is active because your prompt gains a (.venv) prefix. That prefix is the only reliable signal; if it is missing, you are installing globally again. Add .venv/ to your .gitignore — the environment is rebuildable from requirements.txt and should never be committed.

Example
# Create one, once per project
python -m venv .venv

# Activate it
# Windows (PowerShell):
.venv\Scripts\Activate.ps1
# Windows (cmd):
.venv\Scripts\activate.bat
# macOS / Linux:
source .venv/bin/activate

# Your prompt now starts with (.venv)
(.venv) $ python -m pip install requests

# Record what the project needs, so anyone can rebuild it
(.venv) $ python -m pip freeze > requirements.txt

# On another machine
python -m venv .venv && source .venv/bin/activate
python -m pip install -r requirements.txt

# Leave the environment
deactivate
Notes
  • If PowerShell refuses to run the activate script with a message about execution policies, run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned once, or use .venv\Scripts\activate.bat from a plain cmd window instead.

Running Your First Script

There are two ways to run Python and they suit different jobs. The REPL — reached by typing python with no filename — evaluates one line at a time and prints the result of each expression immediately. It is the fastest way to check what a function does or whether a slice gives you what you expected. Nothing you type there is saved, so it is a scratchpad, not a workspace.

A script is a .py file you run with python filename.py. Python executes it top to bottom and exits. This is how real programs are written and how everything in this course should be saved. One difference surprises people moving from the REPL: in a script, a bare expression on its own line produces no output at all. The REPL echoes the value of every expression as a convenience; a script does not, so you must call print() when you want to see something.

Example
# --- In the REPL (python with no filename) ---
# >>> 2 + 2
# 4                <- the REPL echoes the value automatically
# >>> "priodemy".upper()
# 'PRIODEMY'
# >>> exit()       <- or Ctrl+Z then Enter on Windows, Ctrl+D elsewhere

# --- In a script, saved as first_script.py ---
2 + 2                       # computed, then thrown away: no output
print(2 + 2)                # 4

name = input("Your name: ")  # waits for you to type and press Enter
print(f"Ready to learn Python, {name}?")

# Run it:
#   python first_script.py
Notes
  • Never name a file after a module you plan to import — random.py, math.py, json.py. Python searches your own folder first, so your file shadows the real module and import random then imports your empty file. The resulting AttributeError is baffling until you spot the filename.
Ask AI