Getting Started with Python

Install Python 3, virtual environments, and run your first script or REPL session.

Python 3 is the only Python to learn in 2026. Treat the interpreter + venv + pip trio as your baseline toolchain before frameworks.

Core concepts

  1. python3 vs python: On macOS/Linux use python3; Windows installers add py launcher. — Python docs: Using Python
  2. Virtual environments: python -m venv .venv then source .venv/bin/activate — isolates dependencies per project. — Python docs: venv
  3. pip: pip install package inside an active venv; pin versions in requirements.txt or pyproject.toml. — pip getting started
  4. REPL: Quick experiments; save modules as .py files importable by name. — Python docs: Using the interpreter
python
# hello.py
def greet(name: str) -> str:
    return f"Hello, {name}"

if __name__ == "__main__":
    print(greet("iHateReading"))
  1. Shebang & scripts: #!/usr/bin/env python3 for CLI tools made executable. — Python docs: Unix scripts

Concept videos

YouTube lessons for these topics. On a large screen they open in the reading panel next to the roadmap, same as the article links on each core concept.

Explanation

Python feels like writing instructions in plain English compared to lower-level languages — but you still need a disciplined setup or projects become dependency soup.

python3 vs python

Machines often ship old python pointing to Python 2 (deprecated). python3 is explicit. The Windows py launcher picks versions safely. Treat the version number like checking you boarded the right train before it leaves the station.

Virtual environments

A venv is a project-sized bubble: packages installed inside do not leak globally. Without venvs, Project A’s Django version fights Project B’s. Activate the venv in each terminal session (or configure your IDE) before pip install.

pip

pip downloads libraries from PyPI — Python’s app store for code. Pin versions in requirements.txt so production matches your laptop. For new projects, pyproject.toml is the modern metadata home.

REPL

The REPL is instant feedback: import a module, test a function, inspect objects. Move stable code into .py files so you can import, test, and deploy. The REPL is sketching; files are the blueprint.

Shebang & scripts

The shebang line tells Unix “run this file with Python 3.” Combine with chmod +x to create CLI tools (./deploy.py). if __name__ == "__main__" separates library code from script entry when others import your file.

What Is It?

Getting started covers installing CPython, using virtual environments, and running your first module.

pip installs third-party packages into the active environment, recorded in requirements or pyproject files.

The if __name__ == '__main__' guard lets files behave as scripts or importable modules.

Why Should I Care?

Broken PATH or mixed system Python versions cause half of beginner 'it works on my machine' issues.

Every employer expects you to reproduce environments from a repo, not from memory.

Real World Analogy

The Python interpreter is a patient translator: you hand it one line or file at a time, and it executes immediately — no compile step before your first print.

Visual Mental Model

text
python3 script.py
       |
  bytecode (cached .pyc)
       |
  CPython runtime

Beginner Explanation

Install Python 3, create python -m venv .venv, activate it, and run scripts with python file.py. The REPL (python) is for experiments; files are for real work.

Smallest Possible Example

python
def greet(name: str) -> str:
    return f"Hello, {name}"

if __name__ == "__main__":
    print(greet("iHateReading"))

Common Mistakes

❌ Running pip install outside a venv.

You pollute system Python and break OS tools that depend on it.

❌ Naming your script random.py and shadowing the stdlib.

Imports break in confusing ways. Name files after your app, not built-in modules.

❌ Skipping python -m pip on Windows/macOS permission errors.

Installing into user site-packages without a venv is a band-aid, not a habit.

Real Project Example

Poetry and uv wrap the same venv + dependency ideas for teams at scale.

Replit and GitHub Codespaces auto-create venvs so onboarding matches this chapter.

Build This Mini Project

Create a folder with .venv, a main.py, and requirements.txt with one dependency. Run from a fresh clone simulation: create venv, install, execute.

Interview Question

What is a virtual environment?

An isolated directory with its own Python interpreter symlinks and site-packages so project dependencies do not clash with other projects or the OS Python.

Key Takeaways

  • Python 3 + venv + pip is the baseline toolchain.
  • Scripts vs modules — use the main guard.
  • REPL for experiments, files for shipping.
  • Never shadow stdlib module names.

Resources

The 60-second story

You borrow a friend’s kitchen to test a soup. If you use their salt, their oil, and their half-empty spice jar, the soup tastes like their kitchen, not yours. Next week they upgrade the salt and your recipe breaks. A virtual environment is your own labeled shelf in that kitchen. The stove is still the house Python. The jars on your shelf are yours.

On a Mac or Linux the stove is often named python3, because python might be an older pot nobody wants to touch. Windows installers add a py launcher so you can point at the right pot without memorizing a path. You create the shelf with python -m venv .venv, then you step into it with source .venv/bin/activate. The prompt changes. You are no longer grabbing jars from the hallway.

pip is the person who fetches jars onto that shelf. If you run it outside the shelf, you are seasoning the whole house. Pin versions in requirements.txt or pyproject.toml so next month’s “it worked yesterday” has a receipt.

The REPL is tasting a spoonful. A .py file is writing the recipe card so you can cook it again. A shebang, #!/usr/bin/env python3, is taping the card to the fridge and saying any cook in the house should use the Python pot, then marking the card executable so you can run it like a command.

Map the kitchen.

  • The stove is the Python interpreter.
  • python3 or py is “which stove.”
  • .venv is your shelf.
  • pip is the shopper for that shelf only.
  • The REPL is a spoon.
  • A module is a recipe card named something.py.
  • The shebang is the note that tells the house which stove to light.
python
# hello.py
print("soup's on")

Run it with the shelf active: python hello.py. If a teammate clones the repo and skips the shelf, they will import your neighbor’s old requests library and blame the soup. The shelf is the whole point of the first day.

Virtual environments were invented because one global site-packages folder is a shared junk drawer. Two projects, two versions of the same jar, one computer, and suddenly both lunches taste wrong. venv is boring on purpose. Boring is how the soup stays yours.

Mental model: your own shelf in a shared kitchen. The language is installed once. The dependencies are not allowed to wander into the hallway.

You can explain the page if you remember: activate the shelf, install into the shelf, pin the jars, and keep experiments in files once the spoonful tastes right.

Threads in the same domain as this chapter — go deeper on iHateReading without leaving the roadmap.

Smallest AI Agent cover

Smallest AI Agent

Minimal file-reading agent to learn LLM tool loops without framework magic.

AI Agent cover

AI Agent

What agents are and how they differ from a single chat completion.