Day 1 of 80

Environment Setup & First Code

Phase 1: Python Foundation

Here is the comprehensive content for Day 1 of the GenAI Bootcamp.

* # Day 1: 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 with Large Language Models, we need to build the factory where that work happens.

Today, you are not just "installing software." You are building a professional-grade development workbench. By the end of this session, you will have a fully functional coding environment that mirrors what professional software engineers use at companies like Google or OpenAI.

Here is what you are going to master today:

* VS Code (Visual Studio Code): You will set up your primary workspace. We need this because writing code in a standard text editor (like Notepad or Word) is like trying to write a novel on the back of a napkin—it is possible, but painfully inefficient.

* The Terminal: You will learn to control your computer using text commands. We need this because graphical interfaces are often too slow or limited for the heavy lifting required in AI development.

* Virtual Environments (venv): You will learn how to create isolated "sandboxes" for your projects. We need this because different AI projects often require conflicting tools; without isolation, your computer becomes a messy, broken web of dependencies.

* Pip (Package Installer for Python): You will learn how to download code written by others. We need this because in GenAI, we rarely start from scratch—we stand on the shoulders of giants by downloading libraries.

* Your First Python Script: You will write and run a program that speaks back to you.

Let's get started.

The Problem

Imagine you want to build a custom bookshelf. You go to the hardware store, buy a saw, a hammer, and some wood. You build the shelf in your living room. It looks great.

A month later, you want to fix a delicate wristwatch. You go to the store, buy a tiny screwdriver and a magnifying glass. You bring them into the living room, but the room is covered in sawdust from the bookshelf project. You can't find the tiny screws because they are lost in the wood shavings. You try to use the hammer to fix the watch, and you crush it.

This is exactly what happens when beginners start coding without understanding Environment Management.

Look at the error message below. This is the "Pain" we want to avoid.

Error: Package 'openai' requires version 1.0.0, but you have version 0.27.0 installed.
Error: Package 'pandas' conflicts with 'numpy' version 1.21.
Fatal Error: Python environment corrupted.

If you install everything into one global place on your computer (the "living room"), your projects will eventually destroy each other. You might update a library to make Project A work, which instantly breaks Project B.

Furthermore, beginners often try to write code like this:

# A script written in Notepad without an IDE
print("Hello)
# Wait, why isn't this running? 
# Oh, I missed a quote mark.
# But Notepad didn't tell me!

Without a proper Code Editor (IDE), you get no feedback. You are flying blind. You spend hours hunting for a missing comma that a proper tool would have highlighted in red instantly.

The solution is a dedicated Integrated Development Environment (VS Code) and Virtual Environments. We are going to stop treating your computer like a messy living room and start treating it like a laboratory with distinct, clean containment zones.

Let's Build It

We will set up your environment step-by-step. Do not skip steps.

Step 1: Install Python and VS Code

If you have not done this yet, please do so now.
  • Download Python: Go to python.org. Download the latest version (3.10 or newer).
  • * CRITICAL FOR WINDOWS USERS: During installation, you must check the box that says "Add Python to PATH". If you miss this, nothing will work.

  • Download VS Code: Go to code.visualstudio.com and install it.
  • Step 2: Verify Installation via Terminal

    We need to ensure your computer recognizes Python. We will do this using the Command Line (Terminal).

  • Open VS Code.
  • Look at the top menu bar. Click Terminal -> New Terminal.
  • A panel will open at the bottom of the screen with a blinking cursor. This is your command center.
  • Type the following command and press Enter:

    python --version
    
    Note: On some Mac/Linux systems, you might need to type python3 --version. Expected Output:
    Python 3.11.5
    

    (The specific numbers might vary, but as long as you see "Python 3.x.x", you are safe).

    If you see an error saying "command not found," Python is not installed correctly or is not in your PATH.

    Step 3: Create Your Project Folder

    We will create a specific folder for today's work. You can do this through your computer's file explorer, but let's do it the "developer way" in the terminal.

    Type these commands one by one:

    # 1. Make a directory (folder) named 'genai_bootcamp'
    mkdir genai_bootcamp
    
    # 2. Change directory (go inside the folder)
    cd genai_bootcamp
    
    # 3. Make a directory for Day 1
    mkdir day01
    
    # 4. Go inside Day 1
    cd day01
    

    Now, in VS Code, go to File -> Open Folder and select the genai_bootcamp folder you just created.

    Step 4: Create a Virtual Environment (The Sandbox)

    This is the most important step for your future sanity. We are going to create a "virtual environment" inside this folder. This is a self-contained copy of Python just for this project.

    In your VS Code terminal (ensure you are inside the day01 folder), run:

    # Windows
    python -m venv .venv
    
    # Mac / Linux
    python3 -m venv .venv
    
    What just happened?

    You told Python (python) to run a module (-m) called venv (virtual environment) and create a new environment in a folder named .venv.

    You should see a new folder appear in your file explorer on the left named .venv.

    Step 5: Activate the Environment

    Creating the sandbox isn't enough; you have to step inside it.

    Run this command:

    For Windows:
    .venv\Scripts\activate
    
    For Mac/Linux:
    source .venv/bin/activate
    
    How do you know it worked?

    Look at your terminal command line. You should see (.venv) appear in parentheses at the very beginning of the line.

    * Before: C:\Users\Name\genai_bootcamp\day01>

    * After: (.venv) C:\Users\Name\genai_bootcamp\day01>

    If you see that (.venv), you are safe. Any library you install now will live here, and only here.

    Step 6: Write Your First Script

    Now that our lab is built, let's write code.

  • In the VS Code "Explorer" (left sidebar), hover over the day01 folder and click the "New File" icon (it looks like a paper with a plus sign).
  • Name the file main.py. The .py extension tells the computer this is a Python script.
  • Type the following code into the file:
  • import sys
    
    print("--- SYSTEM CHECK ---")
    print("Python is running successfully!")
    print("Current version:", sys.version)
    print("Hello, GenAI Student. Your environment is ready.")
    print("--------------------")
    
  • Save the file (Ctrl+S or Cmd+S).
  • Step 7: Run the Script

    Go back to your terminal (make sure you still see (.venv)).

    Type:

    python main.py
    
    Expected Output:
    --- SYSTEM CHECK ---
    Python is running successfully!
    Current version: 3.11.5 (tags/v3.11.5... etc)
    Hello, GenAI Student. Your environment is ready.
    --------------------
    

    Congratulations. You have just set up a professional development workflow and run your first code.

    Now You Try

    It is time to stretch your legs. Try these three tasks to reinforce what you just did.

  • Modify the Output:
  • Change the main.py file to print your name and your goal for this bootcamp. Run the file again to see the changes.

  • Break It Intentionally:
  • Remove the closing parenthesis ) on the last print statement in your code. Save it and run it.

    * Observe the error message in the terminal. It will say SyntaxError.

    * Read the error—it usually points to the exact line number where the problem is.

    * Fix the code and run it again.

  • The "Pip" Test:
  • We mentioned pip is for installing external tools. Let's try to install a fun little library that generates ASCII art.

    * In your terminal (with .venv active), type: pip install art

    * Update your main.py with this code:

            from art import tprint
            tprint("GenAI")
            

    * Run the script. You should see "GenAI" printed in large block letters.

    Challenge Project

    Objective: Create a script that checks the status of a website.

    This challenge simulates a real-world task: checking if a server is online. You will need to use an external library called requests. This is the most popular Python library in the world, used by almost every AI application to talk to the internet.

    Requirements:
  • Create a new file named check_site.py.
  • Install the requests library using pip inside your virtual environment.
  • Write a script that:
  • * Imports the requests library.

    * Sends a request to https://www.google.com.

    * Prints the "Status Code" of the response (A status code of 200 means "OK").

  • Run the script from the terminal.
  • Hints:

    * To install the library: pip install requests

    * To use it in code: import requests

    * To make a request: response = requests.get("https://www.google.com")

    * To get the status: print(response.status_code)

    Example Output:
    Checking connection to Google...
    Response Code: 200
    Success!
    

    Common Mistakes

    Here are the things that trip up almost every beginner. If these happen to you, do not panic. It is part of the process.

    1. The "Command Not Found" Error

    * The Mistake: Typing python in the terminal and getting pthon: command not found.

    * The Cause: Usually a typo (like pthon instead of python), or Python was installed without the "Add to PATH" checkbox checked.

    * The Fix: Check your spelling first. If spelling is correct, reinstall Python and ensure "Add to PATH" is selected.

    2. The "Module Not Found" Error

    * The Mistake: You try to run code that uses requests or art, and see ModuleNotFoundError: No module named 'requests'.

    * The Cause: You probably forgot to activate your virtual environment before running pip install. You installed the library in the "living room," but your code is looking in the "sandbox."

    * The Fix: Look at your terminal line. Do you see (.venv)? If not, run the activation command (Step 5) and try pip install again.

    3. The "File Not Found" Error

    * The Mistake: Typing python main.py and seeing [Errno 2] No such file or directory.

    * The Cause: Your terminal is looking in the wrong folder.

    * The Fix: Type ls (Mac/Linux) or dir (Windows) to see what files are in your current folder. If you don't see main.py, use cd to move into the correct folder.

    Quick Quiz

    Test your understanding of today's concepts.

    Q1: Why do we use a Virtual Environment (.venv)?

    a) To make Python run faster.

    b) To isolate project dependencies so different projects don't break each other.

    c) To allow us to use the mouse inside the terminal.

    d) To automatically write code for us.

    Answer: b Q2: Which command is used to download and install new external libraries?

    a) python install

    b) download lib

    c) pip install

    d) get package

    Answer: c Q3: If you see SyntaxError: unexpected EOF while parsing, what is the most likely cause?

    a) Your internet connection is down.

    b) You forgot to install Python.

    c) You have an open parenthesis ( or quote " that you forgot to close.

    d) The computer is overheating.

    Answer: c

    What You Learned

    Today, you didn't just write "Hello World." You built a factory.

    * VS Code: Your integrated workbench.

    * Terminal: Your direct line of communication to the operating system.

    * Virtual Environments: Your safety containment protocol.

    * Pip: Your supply chain for external tools.

    Why This Matters for AI:

    In the coming days, we will be using powerful AI libraries like OpenAI, LangChain, and HuggingFace. These are massive, complex collections of code. You cannot write them from scratch. You must use pip to install them, and you must use venv to manage them, or they will conflict with one another.

    You have laid the foundation. Now we can start building the structure.

    Tomorrow: We dive into the raw materials of coding: Variables and Strings. You will learn how to capture user input, manipulate text, and prepare data for the AI to process. See you then!