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.
The toolchain comparison
Section titled “The toolchain comparison”Before writing any code, you need to understand how Python’s toolchain maps to Node’s:
# Node / TypeScript toolchainnode → runtime (executes JS)npm → package manager (installs packages)npx → run a package binary without installing globallytsc → TypeScript compilerpackage.json → project manifestnode_modules/ → installed dependencies (per project)# Python toolchainpython3 → runtime (executes Python)pip → package manager (installs packages)pipx → run a tool without polluting your envmypy/pyright → optional type checker (like tsc)pyproject.toml → project manifest (modern)venv/ → isolated dependency folder (per project)Installing Python
Section titled “Installing Python”macOS (recommended — use Homebrew):
python3 --version # Python 3.12.xpip3 --versionWindows (recommended — use the official installer):
- Download from python.org/downloads
- Check “Add python.exe to PATH” during installation
- Open a new terminal:
python --version
Linux (Ubuntu/Debian):
sudo apt update && sudo apt install python3 python3-pip python3-venvpython3 --versionVirtual 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.
# Node: project isolation is automaticmkdir my-project && cd my-projectnpm init -ynpm install express # goes into ./node_modules# no extra setup needed# Python: you must explicitly create isolationmkdir my-project && cd my-projectpython3 -m venv venv # creates ./venv directorysource venv/bin/activate # macOS/Linux# venv\Scripts\activate # Windows PowerShell
pip install fastapi # installs into ./venv, not globallypython3 script.pyAfter running source venv/bin/activate, your prompt changes to show (venv). Now python and pip point to the local venv. Run deactivate to exit.
Running scripts
Section titled “Running scripts”# TypeScriptnpx ts-node src/index.ts # run directlynpx tsc && node dist/index.js # compile then runnpm run dev # package.json script# Pythonpython3 src/main.py # run directly, no compilepython3 -m module_name # run a module as a scriptpython3 -i src/main.py # run then drop into REPLInstalling and saving dependencies
Section titled “Installing and saving dependencies”# Nodenpm install express # install + save to package.jsonnpm install --save-dev jest # devDependencynpm install # install from package.jsonnpm ci # clean install from package-lock.json# Python (classic workflow)pip install fastapi # installs but does NOT savepip freeze > requirements.txt # snapshot current envpip install -r requirements.txt # install from snapshot
# Modern workflow with pyproject.tomlpip install . # install project deps from pyproject.tomlFull workflow example
Section titled “Full workflow example”Here is a complete “start a new Python project” sequence, mapped to what you do for a Node project:
# Node project setupmkdir api && cd apinpm init -ynpm install express typescript ts-node @types/nodenpx tsc --init# edit tsconfig.json...npm run dev# Python project setupmkdir api && cd apipython3 -m venv venvsource venv/bin/activate # activate venvpip install fastapi uvicorn
# Run the appuvicorn main:app --reload
# Capture deps for teammatespip freeze > requirements.txt