Skip to content

Setup — Installing Python and Creating a Project

Playground note: This is a setup/installation lesson. The steps require a real terminal, a Python installation, and filesystem access — none of which are available inside the browser sandbox. Run the commands below in your own terminal.

Before writing any code, you need to understand how Python’s toolchain maps to Node’s:

TypeScript
# Node / TypeScript toolchain
node → runtime (executes JS)
npm → package manager (installs packages)
npx → run a package binary without installing globally
tsc → TypeScript compiler
package.json → project manifest
node_modules/ → installed dependencies (per project)
Python
# Python toolchain
python3 → runtime (executes Python)
pip → package manager (installs packages)
pipx → run a tool without polluting your env
mypy/pyright → optional type checker (like tsc)
pyproject.toml → project manifest (modern)
venv/ → isolated dependency folder (per project)

macOS (recommended — use Homebrew):

Terminal window
brew install [email protected]
python3 --version # Python 3.12.x
pip3 --version

Windows (recommended — use the official installer):

  1. Download from python.org/downloads
  2. Check “Add python.exe to PATH” during installation
  3. Open a new terminal: python --version

Linux (Ubuntu/Debian):

Terminal window
sudo apt update && sudo apt install python3 python3-pip python3-venv
python3 --version

Virtual environments — the venv equivalent of node_modules

Section titled “Virtual environments — the venv equivalent of node_modules”

In Node, npm install creates node_modules/ inside your project. Each project gets its own copy of every dependency. Python’s equivalent is a virtual environment (venv) — an isolated directory containing a Python interpreter and packages.

Without a venv, pip install installs packages globally and they collide across projects. Always use a venv.

TypeScript
# Node: project isolation is automatic
mkdir my-project && cd my-project
npm init -y
npm install express # goes into ./node_modules
# no extra setup needed
Python
# Python: you must explicitly create isolation
mkdir my-project && cd my-project
python3 -m venv venv # creates ./venv directory
source venv/bin/activate # macOS/Linux
# venv\Scripts\activate # Windows PowerShell
pip install fastapi # installs into ./venv, not globally
python3 script.py

After running source venv/bin/activate, your prompt changes to show (venv). Now python and pip point to the local venv. Run deactivate to exit.

TypeScript
# TypeScript
npx ts-node src/index.ts # run directly
npx tsc && node dist/index.js # compile then run
npm run dev # package.json script
Python
# Python
python3 src/main.py # run directly, no compile
python3 -m module_name # run a module as a script
python3 -i src/main.py # run then drop into REPL
TypeScript
# Node
npm install express # install + save to package.json
npm install --save-dev jest # devDependency
npm install # install from package.json
npm ci # clean install from package-lock.json
Python
# Python (classic workflow)
pip install fastapi # installs but does NOT save
pip freeze > requirements.txt # snapshot current env
pip install -r requirements.txt # install from snapshot
# Modern workflow with pyproject.toml
pip install . # install project deps from pyproject.toml

Here is a complete “start a new Python project” sequence, mapped to what you do for a Node project:

TypeScript
# Node project setup
mkdir api && cd api
npm init -y
npm install express typescript ts-node @types/node
npx tsc --init
# edit tsconfig.json...
npm run dev
Python
# Python project setup
mkdir api && cd api
python3 -m venv venv
source venv/bin/activate # activate venv
pip install fastapi uvicorn
# Run the app
uvicorn main:app --reload
# Capture deps for teammates
pip freeze > requirements.txt
What is the Python equivalent of `node_modules/`?
After `pip install fastapi`, how do you save the dependency so a teammate can reproduce it?
What does `source venv/bin/activate` do?