|
| 1 | +# Local Setup 🖥️ |
| 2 | + |
| 3 | +**Use this guide if you prefer to run everything on your own laptop.** |
| 4 | +You have two paths: **(A) native Python + virtual-env** or **(B) VS Code Dev Container with Docker**. |
| 5 | +Choose whichever feels easier—both lead to the same lessons. |
| 6 | + |
| 7 | +## 1. Prerequisites |
| 8 | + |
| 9 | +| Tool | Version / Notes | |
| 10 | +|--------------------|--------------------------------------------------------------------------------------| |
| 11 | +| **Python** | 3.10 + (get it from <https://python.org>) | |
| 12 | +| **Git** | Latest (comes with Xcode / Git for Windows / Linux package manager) | |
| 13 | +| **VS Code** | Optional but recommended <https://code.visualstudio.com> | |
| 14 | +| **Docker Desktop** | *Only* for Option B. Free install: <https://docs.docker.com/desktop/> | |
| 15 | + |
| 16 | +> 💡 **Tip** – Verify tools in a terminal: |
| 17 | +> `python --version`, `git --version`, `docker --version`, `code --version` |
| 18 | +
|
| 19 | +## 2. Option A – Native Python (quickest) |
| 20 | + |
| 21 | +### Step 1 Clone this repo |
| 22 | + |
| 23 | +```bash |
| 24 | +git clone https://github.com/<your-github>/generative-ai-for-beginners |
| 25 | +cd generative-ai-for-beginners |
| 26 | +``` |
| 27 | + |
| 28 | +### Step 2 Create & activate a virtual environment |
| 29 | + |
| 30 | +```bash |
| 31 | +python -m venv .venv # make one |
| 32 | +source .venv/bin/activate # macOS / Linux |
| 33 | +.\.venv\Scripts\activate # Windows PowerShell |
| 34 | +``` |
| 35 | + |
| 36 | +✅ Prompt should now start with (.venv)—that means you’re inside the env. |
| 37 | + |
| 38 | +### Step 3 Install dependencies |
| 39 | + |
| 40 | +```bash |
| 41 | +pip install -r requirements.txt |
| 42 | +``` |
| 43 | + |
| 44 | +Skip to Section 3 on [API keys](#3-add-your-api-keys) |
| 45 | + |
| 46 | +## 2. Option B – VS Code Dev Container (Docker) |
| 47 | + |
| 48 | +We setup this repository and course with a [development container](https://containers.dev?WT.mc_id=academic-105485-koreyst) that has a Universal runtime that can support Python3, .NET, Node.js and Java development. The related configuration is defined in the `devcontainer.json` file located in the `.devcontainer/` folder at the root of this repository. |
| 49 | + |
| 50 | +>**Why choose this?** |
| 51 | +>Identical environment to Codespaces; no dependency drift. |
| 52 | +
|
| 53 | +### Step 0 Install the extras |
| 54 | + |
| 55 | +Docker Desktop – confirm ```docker --version``` works. |
| 56 | +VS Code Remote – Containers extension (ID: ms-vscode-remote.remote-containers). |
| 57 | + |
| 58 | +### Step 1 Open the repo in VS Code |
| 59 | + |
| 60 | +File ▸ Open Folder… → generative-ai-for-beginners |
| 61 | + |
| 62 | +VS Code detects .devcontainer/ and pops a prompt. |
| 63 | + |
| 64 | +### Step 2 Reopen in container |
| 65 | + |
| 66 | +Click “Reopen in Container”. Docker builds the image (≈ 3 min first time). |
| 67 | +When the terminal prompt appears, you’re inside the container. |
| 68 | + |
| 69 | +## 2. Option C – Miniconda |
| 70 | + |
| 71 | +[Miniconda](https://conda.io/en/latest/miniconda.html?WT.mc_id=academic-105485-koreyst) is a lightweight installer for installing [Conda](https://docs.conda.io/en/latest?WT.mc_id=academic-105485-koreyst), Python, as well as a few packages. |
| 72 | +Conda itself is a package manager, that makes it easy to setup and switch between different Python [**virtual environments**](https://docs.python.org/3/tutorial/venv.html?WT.mc_id=academic-105485-koreyst) and packages. It also comes in handy for installing packages that are not available via `pip`. |
| 73 | + |
| 74 | +### Step 0 Install Miniconda |
| 75 | + |
| 76 | +Follow the [MiniConda installation guide](https://docs.anaconda.com/free/miniconda/#quick-command-line-install?WT.mc_id=academic-105485-koreyst) to set it up. |
| 77 | + |
| 78 | +```bash |
| 79 | +conda --version |
| 80 | +``` |
| 81 | + |
| 82 | +### Step 1 Create a virtual environment |
| 83 | + |
| 84 | +Create a new environment file (*environment.yml*). If you are following along using Codespaces, create this within the `.devcontainer` directory, thus `.devcontainer/environment.yml`. |
| 85 | + |
| 86 | +### Step 2 Populate your environment file |
| 87 | + |
| 88 | +Add the following snippet to your `environment.yml` |
| 89 | + |
| 90 | +```yml |
| 91 | +name: <environment-name> |
| 92 | +channels: |
| 93 | + - defaults |
| 94 | + - microsoft |
| 95 | +dependencies: |
| 96 | +- python=<python-version> |
| 97 | +- openai |
| 98 | +- python-dotenv |
| 99 | +- pip |
| 100 | +- pip: |
| 101 | + - azure-ai-ml |
| 102 | + |
| 103 | +``` |
| 104 | + |
| 105 | +### Step 3 Create your Conda environment |
| 106 | + |
| 107 | +Run the commands below in your command line/terminal |
| 108 | + |
| 109 | +```bash |
| 110 | +conda env create --name ai4beg --file .devcontainer/environment.yml # .devcontainer sub path applies to only Codespace setups |
| 111 | +conda activate ai4beg |
| 112 | +``` |
| 113 | + |
| 114 | +Refer to the [Conda environments guide](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html?WT.mc_id=academic-105485-koreyst) if you run into any issues. |
| 115 | + |
| 116 | +## 2 Option D – Classic Jupyter / Jupyter Lab (in your browser) |
| 117 | + |
| 118 | +> **Who’s this for?** |
| 119 | +> Anyone who loves the classic Jupyter interface or wants to run notebooks without VS Code. |
| 120 | +
|
| 121 | +### Step 1 Ensure Jupyter is installed |
| 122 | + |
| 123 | +To start Jupyter locally, head over to the terminal/command line, navigate to the course directory, and execute: |
| 124 | + |
| 125 | +```bash |
| 126 | +jupyter notebook |
| 127 | +``` |
| 128 | + |
| 129 | +or |
| 130 | + |
| 131 | +```bash |
| 132 | +jupyterhub |
| 133 | +``` |
| 134 | + |
| 135 | +This will start a Jupyter instance and the URL to access it will be shown within the command line window. |
| 136 | + |
| 137 | +Once you access the URL, you should see the course outline and be able to navigate to any `*.ipynb` file. For example, `08-building-search-applications/python/oai-solution.ipynb`. |
| 138 | + |
| 139 | +## 3. Add Your API Keys |
| 140 | + |
| 141 | +Keeping your API keys safe and secure is important when building any type of application. We recommend not to store any API keys directly in your code. Committing those details to a public repository could result in security issues and even unwanted costs if used by a bad actor. |
| 142 | +Here's a step-by-step guide on how to create a `.env` file for Python and add the `GITHUB_TOKEN`: |
| 143 | + |
| 144 | +1. **Navigate to Your Project Directory**: Open your terminal or command prompt and navigate to your project's root directory where you want to create the `.env` file. |
| 145 | + |
| 146 | + ```bash |
| 147 | + cd path/to/your/project |
| 148 | + ``` |
| 149 | + |
| 150 | +2. **Create the `.env` File**: Use your preferred text editor to create a new file named `.env`. If you're using the command line, you can use `touch` (on Unix-based systems) or `echo` (on Windows): |
| 151 | + |
| 152 | + Unix-based systems: |
| 153 | + |
| 154 | + ```bash |
| 155 | + touch .env |
| 156 | + ``` |
| 157 | + |
| 158 | + Windows: |
| 159 | + |
| 160 | + ```cmd |
| 161 | + echo . > .env |
| 162 | + ``` |
| 163 | + |
| 164 | +3. **Edit the `.env` File**: Open the `.env` file in a text editor (e.g., VS Code, Notepad++, or any other editor). Add the following line to the file, replacing `your_github_token_here` with your actual GitHub token: |
| 165 | + |
| 166 | + ```env |
| 167 | + GITHUB_TOKEN=your_github_token_here |
| 168 | + ``` |
| 169 | + |
| 170 | +4. **Save the File**: Save the changes and close the text editor. |
| 171 | + |
| 172 | +5. **Install `python-dotenv`**: If you haven't already, you'll need to install the `python-dotenv` package to load environment variables from the `.env` file into your Python application. You can install it using `pip`: |
| 173 | + |
| 174 | + ```bash |
| 175 | + pip install python-dotenv |
| 176 | + ``` |
| 177 | + |
| 178 | +6. **Load Environment Variables in Your Python Script**: In your Python script, use the `python-dotenv` package to load the environment variables from the `.env` file: |
| 179 | + |
| 180 | + ```python |
| 181 | + from dotenv import load_dotenv |
| 182 | + import os |
| 183 | + |
| 184 | + # Load environment variables from .env file |
| 185 | + load_dotenv() |
| 186 | + |
| 187 | + # Access the GITHUB_TOKEN variable |
| 188 | + github_token = os.getenv("GITHUB_TOKEN") |
| 189 | + |
| 190 | + print(github_token) |
| 191 | + ``` |
| 192 | + |
| 193 | +That's it! You've successfully created a `.env` file, added your GitHub token, and loaded it into your Python application. |
| 194 | + |
| 195 | +🔐 Never commit .env—it’s already in .gitignore. |
| 196 | +Full provider instructions live in [`providers.md`](03-providers.md). |
| 197 | + |
| 198 | +## 4. What’s next? |
| 199 | + |
| 200 | +| I want to… | Go to… | |
| 201 | +|---------------------|-------------------------------------------------------------------------| |
| 202 | +| Start Lesson 1 | [`01-introduction-to-genai`](../01-introduction-to-genai/README.md) | |
| 203 | +| Setup an LLM Provider | [`providers.md`](03-providers.md) | |
| 204 | +| Meet other learners | [Join our Discord](https://aka.ms/genai-discord?WT.mc_id=academic-105485-koreyst) | |
| 205 | + |
| 206 | +## 5. Troubleshooting |
| 207 | + |
| 208 | +| Symptom | Fix | |
| 209 | +|-------------------------------------------|-----------------------------------------------------------------| |
| 210 | +| `python not found` | Add Python to PATH or re-open terminal after install | |
| 211 | +| `pip` cannot build wheels (Windows) | `pip install --upgrade pip setuptools wheel` then retry. | |
| 212 | +| `ModuleNotFoundError: dotenv` | Run `pip install -r requirements.txt` (env wasn’t installed). | |
| 213 | +| Docker build fails *No space left* | Docker Desktop ▸ *Settings* ▸ *Resources* → increase disk size. | |
| 214 | +| VS Code keeps prompting to reopen | You may have both Options active; choose one (venv **or** container)| |
| 215 | +| OpenAI 401 / 429 errors | Check `OPENAI_API_KEY` value / request rate limits. | |
| 216 | +| Errors using Conda | Install Microsft AI libraries using `conda install -c microsoft azure-ai-ml`| |
0 commit comments