Phase 1 · Programming Fundamentals
Virtual Environments & Git
Isolate project dependencies with venv, and version your code with Git & GitHub.
On this page
Why virtual environments?
Each project can need different package versions. A virtual environment (venv) keeps those installs private to the project so they do not clash with other work.
You create a venv once per project, activate it, then install packages with pip.
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pippython3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pipWhen the venv is active, your prompt usually shows (.venv). Deactivate with: deactivate
requirements.txt
Freeze the packages your project needs into requirements.txt so others (and future you) can recreate the environment.
Add .venv/ to .gitignore—never commit the virtual environment folder.
pip install requests
pip freeze > requirements.txt
# on another machine / fresh venv:
pip install -r requirements.txtrequests==2.32.3
python-dotenv==1.0.1Prefer pinning versions in team/AI projects so training day and demo day use the same libraries.
Git basics
Git tracks changes to your files over time. A commit is a snapshot with a message. A repository (repo) is the project Git is watching.
Daily loop: edit → git status → git add → git commit.
git init
git status
git add .
git commit -m "Initial commit: phase 1 day 7"git log --oneline
git diff
git checkout -- filename.py # discard unstaged changes (careful!)Write commit messages in the imperative: "Add tip calculator" not "Added tip calculator".
GitHub remote workflow
GitHub hosts your repo online so you can back it up, collaborate, and show a portfolio.
Typical flow: create an empty GitHub repo → connect remote → push. Use branches for features when projects grow.
git remote add origin https://github.com/YOU/learn-ai-notes.git
git branch -M main
git push -u origin maingit clone https://github.com/YOU/learn-ai-notes.git
cd learn-ai-notes
python -m venv .venv
# activate, then: pip install -r requirements.txtNever commit secrets (.env, API keys). Add them to .gitignore from day one.
Practice
Mini challenge: project bootstrap checklist
On your machine: create a folder practice-day7, add a main.py that prints "Phase 1 complete", create a venv, write a one-line requirements.txt (even if empty of packages, add a comment line), init git, commit, and create a .gitignore that ignores .venv/. In Try It, practice the Python helper that validates a .gitignore list.
# Simulate checking ignore rules (run in Try It)
ignored = [".venv/", ".env", "__pycache__/"]
candidates = [".venv/", "main.py", ".env", "README.md"]
for path in candidates:
# TODO: print "ignore" or "track"
pass
Interactive
Try It in the browser
Powered by Pyodide
Write a requirements.txt with two pinned packages (one per line). Read the file and print each package name before the ==.
Output
—
Errors
—
Check understanding
Lesson quiz
Score 4/5 or higher to mark this day complete.