Learn AI
~45 minIn progress

Phase 1 · Programming Fundamentals

Virtual Environments & Git

Isolate project dependencies with venv, and version your code with Git & GitHub.

~45 min4 sections2 exercisesQuiz · pass 4/5
On this page
  1. 01Why virtual environments?
  2. 02requirements.txt
  3. 03Git basics
  4. 04GitHub remote workflow
  5. 05Mini challenge: project bootstrap checklist
  6. 06Try It
  7. 07Quiz

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.

Create and activate (Windows PowerShell)
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
Create and activate (macOS / Linux)
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip

When 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.

Save and restore dependencies
pip install requests
pip freeze > requirements.txt

# on another machine / fresh venv:
pip install -r requirements.txt
Example requirements.txt
requests==2.32.3
python-dotenv==1.0.1

Prefer 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.

Start a repo and make a commit
git init
git status
git add .
git commit -m "Initial commit: phase 1 day 7"
See history and differences
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.

Connect and push
git remote add origin https://github.com/YOU/learn-ai-notes.git
git branch -M main
git push -u origin main
Clone an existing repo
git clone https://github.com/YOU/learn-ai-notes.git
cd learn-ai-notes
python -m venv .venv
# activate, then: pip install -r requirements.txt

Never 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.

challenge starter
# 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.

1.What is the main purpose of a virtual environment?
2.Which file usually lists pinned packages to reinstall later?
3.What should you typically put in .gitignore for a Python project?
4.Which command stages all changes for the next commit?
5.What does git push do?