8. Chapter review
Your environment is set up; the habits you've started here are the same ones professional developers follow every day. This page summarises the key practices and locks in the concepts with a short quiz.
This chapter wasn't just about installation. It was about building professional habits. Let's review the practices that separate beginners from professional developers.
Project organisation
You created a dedicated api-projects folder in a consistent location. This isn't arbitrary; it's how professionals keep code organised:
- Predictable location.
~/api-projectsor%USERPROFILE%\api-projectsmeans you always know where to find your work - Easy backups. One folder to backup instead of code scattered across your system
- Simple navigation.
cd ~/api-projectsbecomes automatic muscle memory - Clear separation. Your API projects are separate from other code, school assignments, or personal scripts
Professional developers often have a ~/projects or ~/code folder where all their work lives. You're establishing this habit from day one.
Virtual environment discipline
The most important habit you learned: activate your virtual environment before working. This prevents the most common beginner problems:
- Navigate to projects. Open terminal and go to your workspace first
- Activate environment. Turn on your isolated Python workspace
- Verify activation. Check for the
(my-first-api-env)prefix
This three-step ritual becomes automatic with practice. Do it enough times and you'll feel uncomfortable working without it, which is exactly the mindset that prevents bugs.
cd ~/api-projects # macOS/Linux
source my-first-api-env/bin/activate # macOS/Linux
cd %USERPROFILE%\api-projects # Windows
my-first-api-env\Scripts\activate # Windows
Some developers combine these into one command:
cd ~/api-projects && source my-first-api-env/bin/activate
cd %USERPROFILE%\api-projects && my-first-api-env\Scripts\activate
The && operator runs the second command only if the first succeeds, saving you a step.
Tool selection
You installed the requests library instead of using Python's built-in urllib. This demonstrates an important principle: choose tools that make your code readable and maintainable.
Professional developers prioritise code clarity. The requests library lets you write API calls that are immediately understandable, even months later or by other developers. Compare:
| Aspect | urllib (built-in) | requests (installed) |
|---|---|---|
| Lines of code | 10+ for basic request | 4 for the same request |
| Readability | Verbose, unclear intent | Self-documenting |
| JSON handling | Manual parsing required | Automatic with .json() |
| Error handling | Complex exception hierarchy | Intuitive exceptions |
| Headers | Manual dictionary management | Clean parameter passing |
This lesson extends beyond just requests. When you have a choice between a verbose built-in approach and a clearer third-party library, favour clarity. Your future self will thank you.
Verification habits
You tested your setup with a verification script. This is another professional practice: verify your assumptions, don't assume things work.
The setup test script checked:
- Python version meets requirements
- Virtual environment is activated
- Required libraries are installed
- Network connectivity works
Professional developers write tests constantly. They don't trust that code works. They verify it. You're learning this mindset from the beginning.
What you know now
After completing this chapter, you understand:
- Python installation. Verify Python version, understand the difference between Python 2 and 3, and know how to install or upgrade Python on your system.
- Package management. Use pip to install libraries, understand what package managers do, and know why installing packages in virtual environments prevents conflicts.
- Virtual environments. Create isolated Python environments, activate and deactivate them, understand why they're essential, and recognise when they're active.
- Project organisation. Structure your file system professionally, navigate with command line tools, and maintain a clean workspace that's easy to manage.
- Code editor setup. Configure VS Code with Python extensions for syntax highlighting, error detection, and auto-completion. Understand how to create, save, and run Python files.
- Troubleshooting skills. Read error messages carefully, search for solutions effectively, and diagnose common issues like missing PATH variables, activation problems, and permission errors.
Essential habits to remember
Professional developers succeed because they develop good habits early. Make these practices automatic:
- Always activate before working. Check for the
(my-first-api-env)prefix before running any Python commands - Install in activated environments. Never install packages without your virtual environment active
- Keep projects organised. All code goes in your
api-projectsfolder for easy access and backup - Search errors immediately. Don't struggle alone. Almost every setup error has been encountered and solved before
These habits prevent the most common beginner mistakes. They're worth repeating until they become second nature.
Quick knowledge check
Test your understanding of development environment setup and best practices before moving on:
What is a virtual environment and why is it essential for Python development?
A virtual environment is an isolated Python installation that gives each project its own set of libraries and dependencies. It's essential because it prevents conflicts between projects that need different versions of the same library, keeps your system Python clean, and makes projects portable and reproducible.
What are the three steps you should follow every time you start working on your API projects?
1. Navigate to your projects folder: cd ~/api-projects (macOS/Linux) or cd %USERPROFILE%\api-projects (Windows)
2. Activate your virtual environment: source my-first-api-env/bin/activate (macOS/Linux) or my-first-api-env\Scripts\activate (Windows)
3. Verify activation: Check for the (my-first-api-env) prefix in your command prompt
How do you know if your virtual environment is activated?
You'll see the environment name in parentheses at the beginning of your command prompt, like (my-first-api-env). This prefix confirms the environment is active and any packages you install will go into this isolated environment.
What's the difference between pip and pip3?
On older systems where Python 2 and Python 3 coexist, which is less common today, pip may point to Python 2's package manager while pip3 points to Python 3. The safest habit is to run pip through the Python you are using: python -m pip. Check with python -m pip --version to see which Python version it's associated with.
What command creates a new virtual environment named "my-first-api-env"?
python -m venv my-first-api-env
On macOS/Linux systems where python3 is the command, use: python3 -m venv my-first-api-env
Why is the requests library preferred over Python's built-in urllib?
The requests library is significantly simpler and more intuitive than urllib. It makes common request details like headers, encoding, and JSON parsing easier to handle, reducing 10+ lines of complex boilerplate code to 4 readable lines. This makes code more maintainable and less error-prone.
What's the most common mistake beginners make that causes "ModuleNotFoundError"?
Installing packages without the virtual environment activated. The package installs to system Python, then when you try to import it while your virtual environment is active, Python can't find it because they're completely separate Python installations. Always verify the (my-first-api-env) prefix is showing before installing packages.
Common workflow mistakes
These mistakes trip up every beginner. Being aware of them helps you avoid frustration:
Module missing when you run code
Symptom. You get "ModuleNotFoundError" for libraries you know you installed.
Cause. You're running Python without the virtual environment activated, so it can't find libraries installed in that environment.
Fix. Check your command prompt. No (my-first-api-env) prefix? Activate the environment.
Installed package still cannot import
Symptom. python -m pip install requests succeeds, but Python still can't import it.
Cause. You installed to system Python (no environment active), then tried to run code in your virtual environment.
Fix. Activate your environment, then install again. The library will go to the right place.
Environment active in the wrong terminal
Symptom. Environment is activated in one terminal, but commands in another terminal don't work.
Cause. Virtual environment activation only affects the specific terminal window where you activated it.
Fix. Either activate in each terminal, or just use one terminal window for everything.
python still points to Python 2
Symptom. python --version shows Python 2, even though you installed Python 3.
Cause. On older systems, python can point to Python 2 and you need to use python3 instead.
Fix. Use python3 for all commands: python3 --version, python3 script.py, etc.
You're ready for Chapter 3
The groundwork is laid. Chapter 3 is where the real excitement begins. You'll make your first API requests, watch live data appear on your screen, and build working programs that connect to services across the internet.
No more setup, no more configuration. Just writing code that talks to the world.
Open your command line, navigate to api-projects, activate your virtual environment, and let's start building something real.