# How to Set Up the Conda Environment for AI For Beginners: Complete Setup Guide

> Easily set up your conda environment for the AI For Beginners curriculum. Build a reproducible Python stack with PyTorch, TensorFlow, OpenCV and more using our complete setup guide.

- Repository: [Microsoft/AI-For-Beginners](https://github.com/microsoft/AI-For-Beginners)
- Tags: how-to-guide
- Published: 2026-08-03

---

**Run `conda env create --name ai4beg --file .devcontainer/environment.yml` then `conda activate ai4beg` to build a reproducible Python stack with PyTorch, TensorFlow, OpenCV, and all required dependencies.**

This guide walks you through setting up the **Conda environment for AI For Beginners**, Microsoft's open-source curriculum for machine learning education. The repository provides a locked environment definition that eliminates dependency conflicts and ensures every notebook runs identically across Windows, macOS, and Linux systems.

## Where the Environment Definition Lives

The AI For Beginners curriculum centralizes its Conda configuration in [[`.devcontainer/environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/.devcontainer/environment.yml)](https://github.com/microsoft/AI-For-Beginners/blob/main/.devcontainer/environment.yml). A duplicate exists at the repository root for convenience when not using devcontainer workflows.

Key design decisions in this file:

- **Dual channels** (`defaults` and `conda-forge`) maximize package availability
- **Version-pinned core libraries** like `numpy=1.26`, `matplotlib=3.9`, and `scipy=1.13` prevent drift
- **PyTorch channel priority** (`pytorch::pytorch`, `pytorch::torchvision`) for GPU-ready deep learning
- **OpenCV from conda-forge** (`conda-forge::opencv`) for computer vision lessons
- **Delegated pip dependencies** via [`requirements.txt`](https://github.com/microsoft/AI-For-Beginners/blob/main/requirements.txt) for pure-Python packages

## Step-by-Step Conda Environment Setup

### 1. Install Miniconda

Miniconda provides the `conda` package manager without the bloat of Anaconda. Download the appropriate installer for your platform from [docs.conda.io](https://docs.conda.io/en/latest/miniconda.html) and follow the installation prompts.

### 2. Clone the Repository

```bash
git clone https://github.com/microsoft/AI-For-Beginners.git
cd AI-For-Beginners

```

For a faster clone that excludes the large `translations` folder, use sparse checkout as documented in the repository README.

### 3. Create the Environment

```bash
conda env create --name ai4beg --file .devcontainer/environment.yml

```

This command reads the specification exactly as the curriculum authors tested it, building an isolated Python environment named `ai4beg`.

### 4. Activate and Verify

```bash
conda activate ai4beg

```

Confirm all critical packages load correctly:

```python
python -c "import torch, tensorflow, cv2, numpy; print('PyTorch:', torch.__version__); print('TensorFlow:', tensorflow.__version__); print('OpenCV:', cv2.__version__); print('NumPy:', numpy.__version__)"

```

## What's Inside the Environment

Running `conda env create` with the AI For Beginners specification installs:

| Category | Key Packages |
|----------|-------------|
| **Deep Learning** | PyTorch, TorchVision, TorchAudio, TensorFlow |
| **Scientific Computing** | NumPy 1.26, SciPy 1.13, Pandas |
| **Visualization** | Matplotlib 3.9, Seaborn, Plotly |
| **Computer Vision** | OpenCV 4.x, Pillow, scikit-image |
| **Machine Learning** | scikit-learn, XGBoost, LightGBM |
| **Jupyter Ecosystem** | JupyterLab, ipywidgets, nbconvert |

The [`requirements.txt`](https://github.com/microsoft/AI-For-Beginners/blob/main/requirements.txt) referenced in [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) adds specialized libraries like `transformers`, `datasets`, and `gradio` for modern ML workflows.

## Alternative: VS Code Dev Container

The `.devcontainer` folder doubles as a **VS Code Dev Container** configuration. If you have Docker and the Remote - Containers extension installed, VS Code can build and attach to the same environment automatically—no local Conda installation required.

## Troubleshooting Common Issues

- **Conda command not found:** Ensure Miniconda's `bin` (or `Scripts` on Windows) directory is in your PATH, or restart your terminal after installation.

- **Package conflicts:** The environment file uses strict version pins. If you encounter resolution errors, update Conda: `conda update -n base conda`.

- **CUDA/GPU support:** The default environment installs CPU-only PyTorch. For GPU acceleration, modify the PyTorch line in [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) to specify your CUDA version before running `conda env create`.

## Summary

- The **Conda environment for AI For Beginners** is defined in [`.devcontainer/environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/.devcontainer/environment.yml) with locked versions for reproducibility
- Use **`conda env create --name ai4beg --file .devcontainer/environment.yml`** to build the environment exactly as tested
- Activate with **`conda activate ai4beg`** before running any notebooks or scripts
- The environment bundles PyTorch, TensorFlow, OpenCV, and the full scientific Python stack needed for all curriculum labs

## Frequently Asked Questions

### Can I use my existing Anaconda installation instead of Miniconda?

Yes. Any Conda distribution works—the `conda` commands remain identical. Miniconda is simply recommended for its smaller footprint when you're starting fresh.

### How do I update the environment if the curriculum adds new dependencies?

Delete and recreate: run `conda env remove --name ai4beg`, pull the latest repository changes, then repeat the `conda env create` command. Direct updates with `conda env update` can sometimes miss removed packages.

### Does this environment support GPU acceleration?

The base configuration installs CPU-only PyTorch. For NVIDIA GPU support, edit [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) to replace `pytorch::pytorch` with `pytorch::pytorch=cuda11.8` (or your target CUDA version) before creating the environment. TensorFlow GPU support requires compatible NVIDIA drivers separately.