Environment Setup & First Code
What You'll Build Today
Welcome to the start of your journey into Generative AI. Before we can build intelligent agents or chat interfaces, we need a place to work. Imagine trying to build a custom cabinet without a workbench, a saw, or even a hammer. You would just have a pile of wood and frustration.
Today, we are building your digital workbench. We are going to set up a professional-grade development environment that will serve as the foundation for every single line of code you write in this bootcamp.
By the end of this session, you will have a fully functioning setup where you can write, organize, and execute Python code safely.
Here is what you will master today:
* VS Code (Visual Studio Code): You will learn to use an Integrated Development Environment (IDE) so you aren't writing code in a basic text editor like Notepad.
* The Terminal: You will learn to navigate your computer using text commands, giving you direct control over your operating system.
* Python Interpreter: You will install the engine that translates your English-like code into machine instructions.
* Virtual Environments (venv): You will learn to create isolated "sandboxes" for your projects so that installing a tool for one project doesn't break another.
* Pip (Package Installer): You will learn how to download code written by others to save yourself time.
Let's get your workbench ready.
The Problem
To understand why we need a rigorous setup, let's look at what happens when you don't have one.
Imagine you find a tutorial online for an AI project. The author says, "Just run this script!" You download the file, named ai_script.py.
You try to open it, and your computer asks, "How do you want to open this file?" You choose a text editor, and you see this:
import requests
import pandas as pd
data = requests.get("https://api.example.com/data")
df = pd.DataFrame(data.json())
print(df.head())
You stare at it. You type "run" on your keyboard. Nothing happens. You try double-clicking the file. A black box flashes on the screen for a millisecond and disappears.
Frustrated, you finally figure out how to run it via a command line you barely understand, and you get this error:
Traceback (most recent call last):
File "ai_script.py", line 1, in
import requests
ModuleNotFoundError: No module named 'requests'
You panic and search Google. StackOverflow tells you to "install requests." You do that. Then you run it again.
Traceback (most recent call last):
File "ai_script.py", line 2, in
import pandas
ModuleNotFoundError: No module named 'pandas'
It feels like a game of Whack-a-Mole. Even worse, six months later, you try to run a different project, but it requires an older version of pandas. You install the old version, and suddenly, your first project stops working entirely.
This is called "Dependency Hell." It is the number one reason beginners quit before they ever build anything cool. They aren't stopped by the logic; they are stopped by the environment.
We are going to solve this immediately by using Virtual Environments. We will never install software globally. We will create a fresh, clean universe for every project we build.
Let's Build It
We will set up your environment step-by-step. Do not skip steps.
Step 1: Install Python and VS Code
I will assume you have done the physical installation (downloading the installers from python.org and code.visualstudio.com).
Crucial Check:Open your command prompt (Windows: Type cmd in start menu. Mac: Type Terminal in Spotlight).
Type the following command and press Enter:
``bash
python --version
bashNote: On some Macs or Linux systems, you might need to typepython3 --version. Output:Python 3.11.5You should see something like
(or any version starting with 3). If you see an error saying the command is not recognized, you need to reinstall Python and ensure you check the box that says "Add Python to PATH" during installation.Documents/GenAI_BootcampStep 2: Create Your Project Folder
We need a specific place for our files. Do not save code on your Desktop mixed with random screenshots.
Open VS Code. Go to File > Open Folder. Create a new folder somewhere safe (like ) and name this specific folderDay_01_Setup.dirSelect that folder and open it. VS Code will look empty. That is good. This is your clean slate.
Step 3: The Integrated Terminal
Instead of switching between windows, we will use the terminal inside VS Code.
In the top menu, click Terminal > New Terminal. A panel will open at the bottom. This is your command center. You are now "inside" your project folder.
Type this command to see what is in the folder:
* Windows:
ls* Mac/Linux:
.It should show nothing (or just
and..), because the folder is empty.python -m venv venvStep 4: Creating the Virtual Environment (The Sandbox)
This is the most critical step for your career as a developer. We are creating a self-contained box for this project.
In your VS Code terminal, type:
* Windows:
python3 -m venv venv* Mac/Linux:
What just happened?python*
: "Hey Python..."-m venv*
: "...run the module named 'venv' (virtual environment)..."venv*
: "...and name the new environment folder 'venv'."venvYou will see a new folder appear in your file explorer on the left named
. Never edit files inside this folder. This is for the computer, not for you.Step 5: Activating the Sandbox
Creating the box isn't enough; we have to step inside it.
In the terminal, type:
* Windows:
.\venv\Scripts\activate
* Mac/Linux:
bash
source venv/bin/activate
bashThe Result:(venv)Look at your command line prompt. You should now see
in parentheses at the start of the line.(venv)Example:
(venv) C:\Users\You\Day_01_Setup>If you see that
, you are safe. Any library you install now will stay inside this folder and will not mess up your computer.pipStep 6: Installing a Package with Pip
Now that we are in the sandbox, let's install a tool. Python has a massive library of tools called PyPI. We use a tool called
to grab them.requestsWe will install
, a popular tool for talking to the internet.Type:
pip install requests
You will see text scrolling as it downloads. Once it finishes, verify it is there:
bash
pip list
bashOutput:requestsYou will see
listed along with its version number.Day_01_SetupStep 7: Writing and Running Your First Script
Now we write code.
In the left sidebar of VS Code (the file explorer), hover over the name and click the New File icon (it looks like a paper with a plus sign).main.pyName the file .(venv)Type the following code exactly: import sysimport requests
print("--- SYSTEM CHECK ---")
# Check 1: Are we running the correct Python version?print(f"Python Version: {sys.version.split()[0]}")
# Check 2: Can we use the external library we installed?print("Testing 'requests' library...")
try:
response = requests.get("https://www.google.com")
print(f"Connection Successful! Status Code: {response.status_code}")
except Exception as e:
print(f"Connection Failed: {e}")
print("--- SETUP COMPLETE ---")
Save the file (Ctrl+S or Cmd+S). To run it, go back to your terminal (ensure is still there) and type:
python main.py
`
Expected Output:
--- SYSTEM CHECK ---
Python Version: 3.11.5 <-- (Your version may vary)
Testing 'requests' library...
Connection Successful! Status Code: 200
--- SETUP COMPLETE ---
If you see "Status Code: 200", congratulations. You have a working, isolated development environment.
Now You Try
It is time to build muscle memory. Try these three tasks to reinforce what you just did.
1. Modify the Output
Change the
main.py file to print a different message at the start. Instead of "--- SYSTEM CHECK ---", make it print "--- MY FIRST AI ENVIRONMENT ---". Save it and run it again to see the change.
2. The "Deactivate" Experiment
In your terminal, type
deactivate and press Enter. The (venv) text should disappear. Now, try running the script again (python main.py).
What happens?* You should get an error saying No module named 'requests'.
Why?* You stepped out of the sandbox, and the global Python installation doesn't know about the tools inside the sandbox.
Fix it:* Reactivate the environment (refer to Step 5) and run it again to fix it.
3. Install a New Package
While your environment is active, use pip to install a package called
colorama.
* Command:
pip install colorama
* Modify your code to import it: add
import colorama at the top of your file.
* Run the script to ensure it doesn't crash.
Challenge Project: The Setup Gauntlet
To prove you have mastered the environment, you are going to do it all again, from scratch, without looking at the tutorial steps if possible.
The Goal:
Create a script that asks the internet for a joke and prints it.
Requirements:
Create a completely new folder named Day_01_Challenge.
Open that folder in VS Code.
Create a new virtual environment in this folder.
Activate the virtual environment.
Install the requests library.
Create a file named joke.py.
Write code that fetches data from this URL: https://official-joke-api.appspot.com/random_joke
Print the setup and punchline of the joke.
Hints:
* When you use
requests.get(url), the result is in response.json().
* The data coming back will look like a dictionary:
{'setup': '...', 'punchline': '...'}.
* You access dictionary values using brackets, e.g.,
data['setup'].
Example Output:
Setup: Why do programmers prefer dark mode?
Punchline: Because light attracts bugs.
(Note: The actual joke will be random!)
What You Learned
Today was not about writing complex algorithms; it was about professional discipline. You moved from "clicking files" to "engineering an environment."
Here is a summary of the commands you now own:
*
python --version: Checks your engine.
*
python -m venv venv: Builds your sandbox (virtual environment).
*
source venv/bin/activate (or Windows equivalent): Enters the sandbox.
*
pip install [package_name]: Downloads tools into the sandbox.
*
python [filename].py: Runs your code.
Why This Matters for AI:
When we start building AI agents later in this bootcamp, we will need very specific versions of libraries like
openai, langchain, and pytorch`. These libraries are heavy and complex. If you try to manage them without virtual environments, they will conflict with each other, and you will spend days debugging installation errors instead of building AI.
You have now eliminated that risk.
Tomorrow:Now that our workbench is ready, we need materials to work with. Tomorrow, we dive into Variables and Strings—the building blocks of every program. You will learn how to make Python remember information and manipulate text. See you then.