Foundation Guide

Project Setup

📄 36 Pages 🎯 Stage: See It Work 📦 Output: foundation.html

What this page does

Introduces the four skills you will learn in this guide.

Where this fits

This is the starting point. No prior knowledge required.

Explanation

By the end of this guide, you will know how to:

  • Use Mac Terminal — Navigate folders, run commands, manage files
  • Install Python — Get the latest Python on your Mac using Homebrew
  • Use pip — Install, list, and remove Python packages
  • Use venv — Create isolated environments for each project
These are foundational skills. Every Python project you build will use them.

Why this matters

Without these skills, you cannot run Python projects. This guide ensures you have a solid foundation before writing any code.

✓ Checkpoint

⚠ If something breaks here

Nothing to break yet. Move to Page 2.

What this page does

Shows you how to open Terminal on your Mac.

Where this fits

This is your first action. Terminal is where you will run all commands.

Code (this page)

Press: Command + Space
Type: Terminal
Press: Enter

Explanation

Command + Space opens Spotlight Search. Type "Terminal" and press Enter to launch it.

Alternatively:

  • Open Finder
  • Go to Applications → Utilities → Terminal
Terminal is a text-based interface to your computer. Instead of clicking icons, you type commands.

Why this matters

Terminal is how developers interact with their computer. You will use it constantly.

✓ Checkpoint

⚠ If something breaks here

  • If Spotlight doesn't open: Go to System Settings → Keyboard → Shortcuts → Spotlight
  • If Terminal not found: Open Finder → Applications → Utilities → Terminal

What this page does

Explains what you see when Terminal opens.

Where this fits

You have Terminal open. Now understand what you're looking at.

Explanation

You will see something like:

username@MacBook-Pro ~ %

Breaking it down:

  • username — Your Mac username
  • MacBook-Pro — Your computer name
  • ~ — Your current location (home folder)
  • % — The prompt (Terminal is ready for input)
The blinking cursor after % is where you type commands.

Why this matters

Understanding the prompt helps you know where you are and confirms Terminal is ready.

✓ Checkpoint

⚠ If something breaks here

  • If you see $ instead of %: That's fine, older Mac or different shell
  • If no prompt appears: Close Terminal and reopen it

What this page does

Teaches your first Terminal command: pwd.

Where this fits

Terminal is open. Now run your first command.

Code (this page)

pwd

Explanation

Type pwd and press Enter.

pwd stands for "print working directory." It shows your current location in the file system.

You will see something like:

/Users/kevin

This is your home folder. All your files live somewhere inside this.

Why this matters

Knowing where you are is essential. Many commands depend on your current location.

✓ Checkpoint

⚠ If something breaks here

  • command not found: Make sure you typed pwd exactly (lowercase)
  • No output: Press Enter after typing the command

What this page does

Teaches the ls command to see folder contents.

Where this fits

You know where you are. Now see what's there.

Code (this page)

ls

Explanation

Type ls and press Enter.

ls stands for "list." It shows all files and folders in your current location.

You will see something like:

Desktop    Documents    Downloads    Movies    Music    Pictures

These are folders inside your home directory.

Why this matters

ls is how you explore. You will use it constantly to see what files exist.

✓ Checkpoint

⚠ If something breaks here

  • Nothing listed: Your folder might be empty (unlikely for home folder)
  • command not found: Make sure you typed ls exactly (lowercase L, lowercase S)

What this page does

Teaches the cd command to move between folders.

Where this fits

You can see folders. Now move into one.

Code (this page)

cd Desktop

Explanation

Type cd Desktop and press Enter.

cd stands for "change directory." It moves you into a folder.

Your prompt will change:

username@MacBook-Pro Desktop %

Now Desktop appears instead of ~. You are inside the Desktop folder.

Run pwd to confirm:

pwd

Output:

/Users/kevin/Desktop

Why this matters

Navigation is fundamental. You must be in the right folder to work with files.

✓ Checkpoint

⚠ If something breaks here

  • No such file or directory: Check spelling, capitalization matters
  • Use ls first to see exact folder names

What this page does

Teaches how to move up one folder level.

Where this fits

You are in Desktop. Now go back to home.

Code (this page)

cd ..

Explanation

Type cd .. and press Enter.

.. means "parent folder" — the folder containing your current folder.

Your prompt returns to:

username@MacBook-Pro ~ %

The ~ confirms you are back in your home folder.

Why this matters

You need to move both into folders and back out of them.

✓ Checkpoint

⚠ If something breaks here

  • Still in Desktop: Make sure there's a space between cd and ..
  • Type cd ~ to go directly home from anywhere

What this page does

Teaches how to create a new folder.

Where this fits

You can navigate. Now create folders for your projects.

Code (this page)

mkdir projects

Explanation

Type mkdir projects and press Enter.

mkdir stands for "make directory." It creates a new folder.

Verify it exists:

ls

You will see projects in the list.

Why this matters

You will create folders for every project. This keeps your work organized.

✓ Checkpoint

⚠ If something breaks here

  • File exists: A folder named projects already exists (that's fine)
  • Permission denied: You might be in a protected folder, run cd ~ first

What this page does

Teaches how to create an empty file.

Where this fits

You can create folders. Now create files inside them.

Code (this page)

cd projects
touch test.txt

Explanation

First, move into your projects folder with cd projects.

Then, touch test.txt creates an empty file named test.txt.

Verify:

ls

You will see test.txt listed.

Why this matters

Creating files from Terminal is faster than using Finder for quick tasks.

✓ Checkpoint

⚠ If something breaks here

  • File not appearing: Make sure you're in the right folder (pwd to check)
  • Permission denied: Check folder permissions

What this page does

Teaches how to delete a file.

Where this fits

You created a test file. Now remove it.

Code (this page)

rm test.txt

Explanation

Type rm test.txt and press Enter.

rm stands for "remove." It deletes files permanently.

Warning: There is no trash. Deleted files are gone forever.

Verify:

ls

The file is gone.

Why this matters

Cleaning up test files keeps your projects tidy. But be careful — deletion is permanent.

✓ Checkpoint

⚠ If something breaks here

  • No such file: File already deleted or wrong name
  • To delete folders: Use rm -r foldername (the -r means recursive)

What this page does

Teaches how to clean up your Terminal window.

Where this fits

Your Terminal is full of old commands. Clean it up.

Code (this page)

clear

Explanation

Type clear and press Enter.

Your Terminal window becomes blank, with just a fresh prompt.

Keyboard shortcut: Command + K does the same thing.

Why this matters

A clean screen helps you focus. Use it often.

✓ Checkpoint

⚠ If something breaks here

Nothing can break here. If clear doesn't work, Command + K always will.

What this page does

Verifies you have learned the essential Terminal commands.

Where this fits

You have completed the Terminal section. Confirm your skills.

Explanation

You should now be able to:

CommandPurpose
pwdPrint current location
lsList folder contents
cd folderMove into a folder
cd ..Move up one level
mkdir nameCreate a folder
touch nameCreate a file
rm nameDelete a file
clearClean the screen

Why this matters

These eight commands are the foundation. You will use them every day.

✓ Checkpoint

⚠ If something breaks here

Review pages 4-11 for any command you're unsure about.

What this page does

Checks whether Python is already on your Mac.

Where this fits

Terminal basics complete. Now check for Python.

Code (this page)

python3 --version

Explanation

Type python3 --version and press Enter.

If Python is installed, you will see:

Python 3.12.4

(Your version number may differ.)

If you see command not found, Python is not installed. That's fine — we will install it next.

Why this matters

Many Macs have Python pre-installed. Check before installing.

✓ Checkpoint

⚠ If something breaks here

  • command not found is expected if Python isn't installed
  • Continue to Page 14 to install Python

What this page does

Installs Homebrew, the Mac package manager.

Where this fits

Before installing Python, we need Homebrew.

Code (this page)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Explanation

Copy and paste this entire command into Terminal and press Enter.

Homebrew is a "package manager" — it installs software for you.

The installation will:

  • Ask for your Mac password (type it, nothing will appear)
  • Ask you to press Enter to confirm
  • Take a few minutes to download and install
When done, you will see "Installation successful!"

Why this matters

Homebrew makes installing Python (and many other tools) easy and clean.

✓ Checkpoint

⚠ If something breaks here

  • Password not accepted: Type carefully, it's your Mac login password
  • Already installed: Message says "Homebrew is already installed" — that's fine
  • Network error: Check your internet connection

What this page does

Installs the latest Python using Homebrew.

Where this fits

Homebrew is installed. Now use it to install Python.

Code (this page)

brew install python

Explanation

Type brew install python and press Enter.

Homebrew will:

  • Download Python
  • Install it to the correct location
  • Set up the python3 and pip3 commands
This takes 1-2 minutes.

Why this matters

This installs the latest, properly configured Python on your Mac.

✓ Checkpoint

⚠ If something breaks here

  • brew: command not found: Homebrew didn't install correctly, redo Page 14
  • Already installed: Warning: python is already installed — that's fine

What this page does

Confirms Python is installed correctly.

Where this fits

Python was installed. Now verify it works.

Code (this page)

python3 --version

Explanation

Run python3 --version again.

You should see:

Python 3.12.4

(Or a newer version.)

Also check pip:

pip3 --version

You should see:

pip 24.0 from /opt/homebrew/lib/python3.12/site-packages/pip (python 3.12)

Why this matters

Verification confirms everything is set up correctly before you continue.

✓ Checkpoint

⚠ If something breaks here

  • Version not showing: Close Terminal, reopen, try again
  • Wrong version: Run brew upgrade python

What this page does

Explains why we use python3 instead of python.

Where this fits

Python is installed. Understand the naming convention.

Explanation

On Mac, there are often two Pythons:

CommandVersion
pythonPython 2 (old, deprecated)
python3Python 3 (current, use this)

Always use python3 and pip3 to ensure you're using the modern version.

You can check what python points to:

python --version

If it shows Python 2.x, that's the old system Python. Ignore it.

Why this matters

Using the wrong Python causes confusing errors. Always use python3.

✓ Checkpoint

⚠ If something breaks here

Nothing to break. This is informational.

What this page does

Shows how to start Python's interactive mode.

Where this fits

Python is verified. Now run it.

Code (this page)

python3

Explanation

Type python3 and press Enter.

Your prompt changes:

>>>

This is the Python interpreter. You can type Python code directly:

>>> print("Hello, World!")
Hello, World!
>>> 2 + 2
4

Why this matters

The interactive mode is great for testing small pieces of code quickly.

✓ Checkpoint

⚠ If something breaks here

  • No >>> prompt: Make sure you typed python3 not python
  • Syntax error: Python code must be exact, check spelling and quotes

What this page does

Shows how to exit the Python interpreter.

Where this fits

You are in Python's interactive mode. Now exit back to Terminal.

Code (this page)

>>> exit()

Explanation

Type exit() and press Enter.

You return to the normal Terminal prompt:

username@MacBook-Pro ~ %

Alternative: Press Control + D to exit.

Why this matters

You need to switch between Python and Terminal. Know how to exit.

✓ Checkpoint

⚠ If something breaks here

  • Still seeing >>>: Type exit() with parentheses, not just exit
  • Keyboard shortcut: Control + D always works

What this page does

Verifies you have installed and can run Python.

Where this fits

You have completed the Python installation section.

Explanation

You should now be able to:

TaskCommand
Check Python versionpython3 --version
Check pip versionpip3 --version
Start Pythonpython3
Exit Pythonexit()

Why this matters

Python is installed and working. You can now install packages and run scripts.

✓ Checkpoint

⚠ If something breaks here

Review pages 13-19 for any step you missed.

What this page does

Explains what pip is and why you need it.

Where this fits

Python is installed. Now understand how to add functionality.

Explanation

pip stands for "Pip Installs Packages."

Python itself is basic. Pip lets you install packages — pre-written code that adds features:

PackageWhat It Does
requestsMake web requests
pandasWork with data tables
pygameCreate games
flaskBuild websites

Instead of writing everything from scratch, you install packages others have made.

Why this matters

Every real Python project uses packages. pip is how you get them.

✓ Checkpoint

⚠ If something breaks here

Nothing to break. This is informational.

What this page does

Confirms pip is working on your system.

Where this fits

You understand what pip is. Now verify it works.

Code (this page)

pip3 --version

Explanation

Run pip3 --version in Terminal.

You should see something like:

pip 24.0 from /opt/homebrew/lib/python3.12/site-packages/pip (python 3.12)

This confirms:

  • pip is installed
  • Which Python it's connected to
  • Where it's located

Why this matters

Verifying pip works before using it saves debugging time later.

✓ Checkpoint

⚠ If something breaks here

  • command not found: Run python3 -m pip --version instead
  • Old version: Run pip3 install --upgrade pip

What this page does

Teaches how to install a Python package.

Where this fits

pip is verified. Now use it to install something.

Code (this page)

pip3 install requests

Explanation

Type pip3 install requests and press Enter.

pip will:

  • Download the requests package from the internet
  • Install it on your system
  • Show "Successfully installed requests-2.x.x"
requests is a popular package for making web requests. We're using it as an example.

Why this matters

This is how you add any package to Python. The syntax is always pip3 install packagename.

✓ Checkpoint

⚠ If something breaks here

  • Permission denied: You may need to use a virtual environment (covered soon)
  • Network error: Check your internet connection

What this page does

Shows how to see what packages are installed.

Where this fits

You installed a package. Now see all installed packages.

Code (this page)

pip3 list

Explanation

Type pip3 list and press Enter.

You will see a table:

``` Package Version

Why this matters

Knowing what's installed helps you manage your environment and debug issues.

✓ Checkpoint

⚠ If something breaks here

  • Empty list: That's unusual, but pip itself should appear
  • Long list: System Python may have many pre-installed packages

What this page does

Shows how to remove a package.

Where this fits

You can install and list packages. Now remove one.

Code (this page)

pip3 uninstall requests

Explanation

Type pip3 uninstall requests and press Enter.

pip will ask: Proceed (Y/n)?

Type Y and press Enter to confirm.

You will see "Successfully uninstalled requests-2.x.x"

Why this matters

Sometimes you need to remove packages — to fix conflicts or clean up.

✓ Checkpoint

⚠ If something breaks here

  • Not installed: Package wasn't there (check spelling)
  • Re-install it: pip3 install requests (we'll use it later)

What this page does

Explains the requirements.txt file.

Where this fits

You can install packages one at a time. But projects need many packages.

Explanation

A requirements.txt file lists all packages a project needs:

requests==2.31.0
pandas==2.0.3
numpy==1.24.3

Each line is a package name and version.

When you share your project, others can install everything with one command.

Why this matters

requirements.txt ensures everyone has the exact same packages. This prevents "it works on my machine" problems.

✓ Checkpoint

⚠ If something breaks here

Nothing to break. This is informational.

What this page does

Shows how to create a requirements.txt file.

Where this fits

You understand what requirements.txt is. Now create one.

Code (this page)

pip3 freeze > requirements.txt

Explanation

First, make sure you're in your projects folder:

cd ~/projects

Then run pip3 freeze > requirements.txt.

  • pip3 freeze lists all installed packages with versions
  • > redirects output to a file
  • requirements.txt is the filename
View the file:

cat requirements.txt

Why this matters

This is how you document your project's dependencies for others (or yourself later).

✓ Checkpoint

⚠ If something breaks here

  • Empty file: No packages installed (that's okay for now)
  • No such file or directory: Make sure you're in a folder you can write to

What this page does

Shows how to install all packages from requirements.txt.

Where this fits

You created a requirements.txt. Now use one.

Code (this page)

pip3 install -r requirements.txt

Explanation

The -r flag tells pip to read from a file.

pip will install every package listed in requirements.txt.

This is how you:

  • Set up a project someone shared with you
  • Restore your environment on a new computer
  • Match a teammate's setup exactly

Why this matters

One command installs everything. No manual package-by-package installation.

✓ Checkpoint

⚠ If something breaks here

  • No such file: Make sure requirements.txt exists in current folder
  • Version conflicts: The file may have outdated versions

What this page does

Verifies you understand pip and package management.

Where this fits

You have completed the pip section.

Explanation

You should now be able to:

TaskCommand
Install a packagepip3 install packagename
List packagespip3 list
Uninstall a packagepip3 uninstall packagename
Save dependenciespip3 freeze > requirements.txt
Install from filepip3 install -r requirements.txt

Why this matters

Package management is essential for every Python project.

✓ Checkpoint

⚠ If something breaks here

Review pages 21-28 for any command you're unsure about.

What this page does

Explains why virtual environments exist.

Where this fits

You can install packages globally. But that causes problems.

Explanation

Problem: Different projects need different package versions.

  • Project A needs requests==2.25.0
  • Project B needs requests==2.31.0
If you install globally, one project breaks.

Solution: Virtual environments.

A venv is an isolated Python environment. Each project gets its own:

  • Python interpreter
  • Installed packages
  • requirements.txt
Projects don't interfere with each other.

Why this matters

Professional Python development requires virtual environments. Always use them.

✓ Checkpoint

⚠ If something breaks here

Nothing to break. This is informational.

What this page does

Creates your first virtual environment.

Where this fits

You understand why venv matters. Now create one.

Code (this page)

cd ~/projects
mkdir my-first-project
cd my-first-project
python3 -m venv venv

Explanation

Step by step:

  • cd ~/projects — Go to your projects folder
  • mkdir my-first-project — Create a project folder
  • cd my-first-project — Enter the folder
  • python3 -m venv venv — Create a virtual environment
The -m venv runs Python's venv module. The second venv is the folder name (convention).

Check it was created:

ls

You should see a venv folder.

Why this matters

Every project should start with creating a venv.

✓ Checkpoint

⚠ If something breaks here

  • No module named venv: Run brew install python again
  • Permission denied: Check folder permissions

What this page does

Shows how to activate your virtual environment.

Where this fits

You created a venv. Now activate it.

Code (this page)

source venv/bin/activate

Explanation

Type source venv/bin/activate and press Enter.

Your prompt changes:

(venv) username@MacBook-Pro my-first-project %

The (venv) prefix means the virtual environment is active.

Now when you run pip3 install, packages go into this venv only.

Why this matters

You must activate the venv before working on a project. Otherwise packages install globally.

✓ Checkpoint

⚠ If something breaks here

  • No such file: Make sure you're in the folder containing venv
  • Wrong path: It's venv/bin/activate not venv/activate

What this page does

Shows how to exit the virtual environment.

Where this fits

The venv is active. Now learn to deactivate it.

Code (this page)

deactivate

Explanation

Type deactivate and press Enter.

Your prompt returns to normal:

username@MacBook-Pro my-first-project %

The (venv) prefix is gone. You are back to the global Python.

Why this matters

When switching projects, deactivate one venv before activating another.

✓ Checkpoint

⚠ If something breaks here

  • command not found: You weren't in an active venv
  • This command only works when a venv is active

What this page does

Summarizes the benefits of virtual environments.

Where this fits

You can create, activate, and deactivate venvs. Understand why.

Explanation

Always use venv because:

BenefitExplanation
IsolationProject A's packages don't affect Project B
Reproducibilityrequirements.txt captures exact versions
Clean uninstallDelete the venv folder, everything's gone
No sudoInstall packages without admin rights
Version testingTest different package versions easily

Best practice: Create a venv as the first step for every new project.

Why this matters

Professional developers always use virtual environments. It's an industry standard.

✓ Checkpoint

⚠ If something breaks here

Nothing to break. This is informational.

What this page does

Verifies you can manage virtual environments.

Where this fits

You have completed the venv section.

Explanation

You should now be able to:

TaskCommand
Create a venvpython3 -m venv venv
Activate (Mac)source venv/bin/activate
Deactivatedeactivate
Check if activeLook for (venv) in prompt

Typical workflow:

mkdir new-project
cd new-project
python3 -m venv venv
source venv/bin/activate
pip3 install requests
pip3 freeze > requirements.txt

Why this matters

This workflow is the foundation of every Python project.

✓ Checkpoint

⚠ If something breaks here

Review pages 30-34 for any concept you're unsure about.

What this page does

Confirms you have mastered all skills in this guide.

Where this fits

This is the end. Verify everything works together.

Explanation

Complete this final test:

cd ~/projects
mkdir test-project
cd test-project
python3 -m venv venv
source venv/bin/activate
pip3 install requests
pip3 freeze > requirements.txt
cat requirements.txt
python3 -c "import requests; print('Success!')"
deactivate

If you see "Success!" — you have completed the guide.

You can now:

  • Navigate with Terminal
  • Install and run Python
  • Manage packages with pip
  • Isolate projects with venv

Why this matters

You are ready to build Python projects. This foundation supports everything you'll create.

✓ Checkpoint

⚠ If something breaks here

  • Review the specific section where the error occurred
  • Each skill builds on the previous one

Contents