Tools, Workflow, and Git
Set up a productive environment, manage dependencies, and collaborate effectively with Git and GitHub.
Content
Installing Python and Node
Versions:
Watch & Learn
AI-discovered learning video
Sign in to watch the learning video for this topic.
Installing Python and Node for CS50: Tools, Workflow, and Git
"If the web is a kitchen, Python and Node are your knives — get the right ones, keep them sharp, and don’t drag a meat cleaver to a sushi task."
You're already comfortable with version control, linting, and picking the right editor. Now we put those tools where the rubber meets the runway: your local environment. This guide walks through installing Python and Node the CS50 way — reliable, reproducible, and Git-friendly — while avoiding the usual version/PATH chaos.
Why this matters (quick recap)
- You need a consistent Python 3 and Node (LTS) experience across projects and teammates.
- Proper installs make linters, formatters, virtual environments, and CI behave predictably (you learned linting earlier).
- Git cleanliness: we’ll avoid committing virtual environments and node_modules, and we’ll track manifest files like requirements.txt and package-lock.json.
What you'll get here
- Platform-specific quick commands (macOS, Linux/WSL, Windows).
- Tips on version managers (pyenv, nvm) — highly recommended.
- How to create virtual environments and package manifests.
- Git hints (.gitignore and what to commit).
1) Decide how you want to manage versions (short answer)
- Use pyenv for Python version management (if you switch Python versions).
- Use nvm for Node (industry standard).
- On Windows: prefer WSL for a Linux-like dev environment; otherwise use official installers.
Why? Global installs, PATH issues, and system Python versions are the most common source of “it works on my machine” disasters.
2) Install commands (pick your OS)
macOS (recommended: Homebrew + pyenv + nvm)
Commands (run in Terminal):
# Install Homebrew if you don't have it
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew update
brew install pyenv
brew install node # or install nvm if you prefer nvm (see below)
# If using nvm (recommended for Node versions):
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
# then restart terminal and run: nvm install --lts
Linux / WSL (Ubuntu example)
# Update
sudo apt update && sudo apt upgrade -y
# Python
sudo apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git
# Option 1: system python
sudo apt install -y python3 python3-venv python3-pip
# Option 2: install pyenv (recommended for multiple versions)
curl https://pyenv.run | bash
# then follow the pyenv post-install steps and run: pyenv install 3.x.x
# Node: use nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
# restart shell then: nvm install --lts
Windows
- Best: install WSL (Windows Subsystem for Linux) and follow the Linux steps:
wsl --installin PowerShell (Windows 10/11). - If not using WSL: install from python.org and nodejs.org installers. But be careful about PATH conflicts and prefer nvm-windows if you need version switching.
3) Verify installs (always do this)
python --version # expect 3.x
python3 --version # on some systems
pip --version
node --version # LTS recommended
npm --version
nvm --version # if using nvm
pyenv --version # if using pyenv
If python points to Python 2 on your system, use python3 or fix PATH/pyenv.
4) Project workflow: virtualenv + package manifests
Always work inside a project directory. Example setup for a new Python + Node project:
mkdir mysite && cd mysite
# Python virtual environment
python3 -m venv venv
source venv/bin/activate # Windows (PowerShell): venv\Scripts\Activate.ps1
pip install --upgrade pip
pip install flask # or django ...
pip freeze > requirements.txt
# Node
npm init -y
npm install --save-dev eslint prettier # for linting and formatting
# if you need a tool once: npx create-react-app .
Notes:
- Commit requirements.txt (or Pipfile/Pipfile.lock if using pipenv) to Git.
- Commit package.json and package-lock.json for Node.
5) Integrating linting and editor settings
You already learned linting and editors. Connect them:
- Install Python linters/formatters inside your venv or via pipx:
pip install black flake8. - Install ESLint/Prettier locally:
npm install --save-dev eslint prettier. - Configure your editor (VS Code): select the project Python interpreter (the venv) and enable format on save.
This keeps per-project behavior stable and reproducible across teammates.
6) Git hygiene: what to ignore and what to commit
Add a .gitignore (essential bits):
# Python
venv/
__pycache__/
*.pyc
# Node
node_modules/
# Env files
.env
# Editor
.vscode/
# OS
.DS_Store
Commit: requirements.txt, Pipfile.lock, package.json, package-lock.json. Don’t commit venv or node_modules.
7) Troubleshooting quick hits
- If
pythonis wrong: trypython3or install pyenv and set local version:pyenv local 3.x.x. - pip vs pip3 confusion:
python3 -m pip install <pkg>always works. - PATH problems after installing nvm/pyenv: restart your terminal or source the profile file.
- Permission errors installing global packages: avoid using sudo; prefer per-project installs or use nvm/pyenv.
Key takeaways (TL;DR)
- Use pyenv and nvm to avoid version headaches. Use WSL on Windows for a Linux-like setup.
- Always create a Python virtual environment: don’t install project deps globally.
- Commit manifest files (requirements.txt, package-lock.json) to Git — but ignore venv/ node_modules.
- Hook up your linters/formatters in the project so your editor + CI reproduce the same behavior.
"A consistent environment is the difference between ‘it worked’ and ‘it worked for everyone’."
Quick checklist before your first commit
- python --version shows 3.x
- node --version is LTS
- venv created and activated
- requirements.txt and package-lock.json/package.json present
- .gitignore excludes venv and node_modules
- Editor configured to use project interpreter
Good. Now go make something that breaks the internet in a responsible, linted, version-controlled way.
Comments (0)
Please sign in to leave a comment.
No comments yet. Be the first to comment!