Orientation and Python Environment Setup
Set up the Python environment, tools, and workflows you will use throughout the course.
Content
Command Line Basics
Versions:
Watch & Learn
AI-discovered learning video
Command Line Basics: Your AI Project's Secret Superpower
The terminal is not angry. It is just concise. Treat it like a very literal coworker who only speaks in verbs.
Why are we here (again)?
Remember how, in Project Structure, we gave your repo a skeleton with src/, data/, and notebooks/? And in Git and GitHub, we made your code immortal on the internet? Great. Now we meet the social club where both of them hang out: the command line.
This is where you will:
- Run Python scripts like a boss
- Set up and activate virtual environments (your AI project's oxygen mask)
- Move through your project faster than any GUI clickathon
- Automate repeatable tasks so you can save energy for, you know, AI
If Git is the memory and structure is the body, the command line is the nervous system. Time to wire it up.
Opening the terminal (aka, summoning the text dragon)
- macOS: Open Terminal or iTerm
- Linux: You already know. Ctrl+Alt+T or your preferred terminal
- Windows: Use PowerShell (not the ancient cmd)
- VS Code: View > Terminal (best option to stay inside your project)
A typical prompt looks like:
username@machine project-path $
It is waiting for a command. Like a loyal dog, but faster and with fewer zoomies.
Pro tips before we sprint:
- Ctrl + C: cancel a stuck command
- Up/Down arrows: command history
- Tab: auto-completion (your new best friend)
- clear or cls: clean the screen
Paths, but make them vibes
Your project probably looks something like:
ai-intro/
├─ src/
│ ├─ main.py
│ └─ utils/
├─ data/
│ └─ raw/
└─ notebooks/
Key path concepts you must tattoo onto your soul:
- Absolute path: from the root of your file system, e.g., /Users/you/ai-intro
- Relative path: from where you currently are, e.g., src/utils
- . means current directory
- .. means parent directory
- ~ means your home directory
- Spaces in paths need quotes, e.g., 'My Projects/ai-intro'
Check where you are and what is around you:
# Where am I?
pwd
# What is here?
ls
# Go into src, then back out
cd src
cd ..
On Windows PowerShell, ls, cat, rm, mv, and cp are convenient aliases that work like macOS/Linux. If you ever get stuck, you can use full cmdlets like Get-ChildItem, Remove-Item, etc.
Navigation and file wrangling
Let us move like we mean it.
- Create things:
- mkdir data/processed
- macOS/Linux: touch src/utils/helpers.py
- Windows PowerShell: New-Item -ItemType File src/utils/helpers.py
- Copy and move:
- cp src/main.py src/main_backup.py
- mv src/main_backup.py src/old_main.py
- Remove with care:
- rm old_file.txt
- rm -r junk_folder
- PowerShell equivalent also supports rm -Recurse
- Peek inside files:
- cat src/main.py
- less src/main.py (q to quit)
- head -n 5 data/raw/some.csv
- tail -n 10 logs/app.log
Wildcards are your productivity multiplier:
- ls data/raw/*.csv lists all csv files
- rm -r data/temp_* deletes folders that start with temp_ (double-check before you press enter)
Why do people keep misunderstanding this? Because GUIs hide the map. The CLI shows you the coordinates.
Redirection and pipes: command choreography
Combine small, focused commands like Lego blocks.
- Redirect output to a file:
- echo hello > notes.txt (creates or overwrites)
- echo another line >> notes.txt (appends)
- Pipe output from one command to another:
- cat data/raw/big.csv | head -n 5
- ls src | wc -l (how many files? macOS/Linux)
- PowerShell count: ls src | Measure-Object | Select-Object -ExpandProperty Count
- Quick grep vibes:
- macOS/Linux: cat src/main.py | grep import
- PowerShell: Select-String -Path src/main.py -Pattern import
The CLI is like texting your computer in its mother tongue. Short, specific, and very literal.
Python from the terminal (the main event)
You have got Python. Prove it:
# macOS/Linux
python3 --version
# Windows
py -3 --version
# or
python --version
Virtual environment time. This keeps your AI project dependencies isolated from your global computer health.
# From your project root
python -m venv .venv
# Activate it
# macOS/Linux
source .venv/bin/activate
# Windows PowerShell
.\.venv\Scripts\Activate.ps1
# Your prompt should now show (.venv)
# Upgrade pip and install deps
python -m pip install --upgrade pip
pip install -r requirements.txt # if you have one
# Confirm
which python # macOS/Linux
where.exe python # Windows cmd
Get-Command python # Windows PowerShell
Run your code:
python src/main.py
Run a module directly (handy for tools):
python -m venv --help
python -m pip list
Good housekeeping:
- Add .venv to .gitignore (you do not need 300 MB of site-packages in your repo)
- Deactivate when done: deactivate
Your Git powers, now turbocharged by CLI
You learned Git already; now stitch it into your daily terminal flow:
# Where am I in Git-land?
git status
# Save your progress
git add -A
git commit -m 'Finish data loader for iris dataset'
# Sync with GitHub
git pull --rebase
git push
Pro tip: Branching is just paths for commits. Same navigation mindset.
Cross-platform quick table
| Task | macOS/Linux | Windows PowerShell |
|---|---|---|
| Where am I | pwd | pwd |
| List files | ls | ls (alias for Get-ChildItem) |
| Change directory | cd path | cd path |
| Make directory | mkdir name | mkdir name |
| Create file | touch file.py | New-Item -ItemType File file.py |
| Remove file | rm file | rm file |
| Remove folder | rm -r folder | rm -Recurse folder |
| Show file | cat file.py | cat file.py (alias for Get-Content) |
| Search in file | grep pattern file | Select-String -Pattern pattern -Path file |
| Clear screen | clear | cls or Clear-Host |
| Which Python | which python | Get-Command python or where.exe python |
If you prefer Unix-like commands on Windows, install Git Bash or use Windows Subsystem for Linux (WSL). But PowerShell is fine for 99 percent of this course.
Mini-lab: 8 moves to feel dangerous (the good kind)
- Open the terminal in your ai-intro project root
- Verify your structure:
pwd
ls
- Make a place for intermediate data:
mkdir -p data/interim # PowerShell: mkdir data/interim
- Create a new script and a log file:
# macOS/Linux
touch src/utils/io_helpers.py
# PowerShell
New-Item -ItemType File src/utils/io_helpers.py
# Everyone
echo run started > logs.txt
- Activate your virtual environment and install numpy:
python -m venv .venv
source .venv/bin/activate # or .\.venv\Scripts\Activate.ps1 on Windows
python -m pip install --upgrade pip
pip install numpy
- Sanity-check Python paths:
python -c 'import sys,site; print(sys.executable); print(site.getsitepackages())'
- Run your main script:
python src/main.py
- Commit your changes like the responsible scientist you are:
git add -A
git commit -m 'Add io_helpers and set up venv with numpy'
git push
If anything goes sideways, use git status and retrace your steps with the up arrow. The terminal keeps receipts.
Gotchas and power tips
- Quote paths with spaces: cd 'My Projects/ai-intro'
- Use tab to avoid typos; it is both faster and calmer
- rm is forever. If you are nervous, use trash-cli or confirm flags, or do a dry-run with echo
- Use history or Get-History to re-run useful commands
- In VS Code, you can run code . to launch the editor from the current folder
Wrap-up: what just happened?
You learned how to navigate, create, inspect, and destroy files from the CLI; how to chain commands like a pro; and how to run Python and manage a virtual environment. This plugs directly into your project structure and your Git workflow, turning all three into a smooth daily ritual.
Key takeaways:
- The CLI is faster because it is composable
- Relative paths make you nimble inside your project
- Virtual environments keep dependencies civilized
- Git and the terminal are best friends; use them together
Final thought: You do not have to memorize every command. Memorize patterns. The rest is tab-complete and muscle memory.
Now go talk to your computer. Politely. With verbs.
Comments (0)
Please sign in to leave a comment.
No comments yet. Be the first to comment!