# How to Set Up Conda Environment from environment.yml for AI for Beginners

> Easily set up your conda environment from environment.yml for the Microsoft AI For Beginners curriculum. Follow simple commands to install all dependencies and start learning AI today.

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

---

**Run `conda env create --name ai4beg --file environment.yml` to build the complete Python environment for Microsoft's AI curriculum, then activate with `conda activate ai4beg`.**

The [microsoft/AI-For-Beginners](https://github.com/microsoft/AI-For-Beginners) repository provides a pre-configured Conda environment that bundles all dependencies needed for the Jupyter notebooks, GPU-accelerated labs, and the Vue.js quiz application. Using the [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) file ensures you get version-locked packages that match the curriculum's tested configuration, avoiding common dependency conflicts between PyTorch, TensorFlow, and OpenCV.

## Where to Find the environment.yml File

The master environment definition lives at [[`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml)](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) in the repository root.

According to the source, this YAML declares:

- **Channels** – `defaults`, `conda-forge`, and `pytorch` (for GPU-accelerated deep learning)
- **Core dependencies** – `python`, `ipykernel`, `jupyter`, `numpy=1.26`, `matplotlib=3.9`, `scikit-learn`, `scipy=1.13`, `requests=2.32`, `setuptools`
- **OpenCV** – pulled from `conda-forge` for computer vision lessons
- **Pip integration** – a `pip:` block that installs everything from [[`requirements.txt`](https://github.com/microsoft/AI-For-Beginners/blob/main/requirements.txt)](https://github.com/microsoft/AI-For-Beginners/blob/main/requirements.txt), including **TensorFlow 2.17** and **Keras 3.5**

The file is referenced in [[`lessons/0-course-setup/setup.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/lessons/0-course-setup/setup.md)](https://github.com/microsoft/AI-For-Beginners/blob/main/lessons/0-course-setup/setup.md), the official setup guide for the course.

## Step-by-Step: Creating the Conda Environment

### 1. Clone the Repository

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

```

If you already have the code, simply ensure [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) is in your working directory.

### 2. Create the Environment

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

```

The `--name ai4beg` flag creates a predictably named environment that the curriculum's instructions reference throughout. The `conda env create` command:

1. Resolves channels in priority order (`defaults` → `conda-forge` → `pytorch`)
2. Installs all Conda-packaged dependencies
3. Executes the embedded `pip` block to install TensorFlow, Keras, and other PyPI-only packages

This single command typically takes 5–15 minutes depending on download speed and whether CUDA toolkits are installed.

### 3. Activate the Environment

```bash
conda activate ai4beg

```

Activation puts the environment's Python interpreter and libraries on your `$PATH` and registers the `ipykernel` for Jupyter notebook integration.

### 4. Verify Installation

```bash
python -c "import torch, tensorflow; print('Torch:', torch.__version__, 'TF:', tensorflow.__version__)"

```

Expected output shows **PyTorch** and **TensorFlow** versions matching those pinned in [`requirements.txt`](https://github.com/microsoft/AI-For-Beginners/blob/main/requirements.txt). If you see import errors, check that activation succeeded (`which python` should point to your Conda environment path).

### 5. Launch Jupyter

```bash
jupyter notebook lessons/3-NeuralNetworks/05-Frameworks/IntroPyTorch.ipynb

```

All notebooks in `lessons/` are configured to use the `ai4beg` kernel automatically once the environment is active.

## Why the environment.yml Structure Matters

### Channel Priority Prevents Conflicts

The YAML's channel order (`defaults`, `conda-forge`, `pytorch`) ensures packages with multiple builds resolve correctly. OpenCV, for example, is explicitly pulled from `conda-forge` rather than potentially outdated `defaults` builds.

### Version Pinning Guarantees Reproducibility

Pinned versions like `numpy=1.26`, `matplotlib=3.9`, and `scipy=1.13` prevent breaking changes from newer releases. This is critical for educational content where API shifts in TensorFlow or PyTorch would invalidate exercise code.

### The Pip Block Bridges Ecosystems

The `pip:` section in [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) delegates to [`requirements.txt`](https://github.com/microsoft/AI-For-Beginners/blob/main/requirements.txt) for packages not available in Conda channels:

- **TensorFlow 2.17** – Google's deep learning framework
- **Keras 3.5** – high-level neural network API
- Additional utilities like `tqdm`, `Pillow`, and `pandas`

Installing these after Conda packages preserves correct dependency hierarchies—Conda manages compiled binaries (CUDA, MKL), while pip handles pure-Python machine learning libraries.

## Complete Setup Script

```bash
#!/bin/bash

# Full environment setup for AI for Beginners

# Clone repository

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

# Create and activate environment

conda env create --name ai4beg --file environment.yml
conda activate ai4beg

# Verify key imports

python - <<'PY'
import torch
import tensorflow as tf
import numpy as np
import cv2

print(f"PyTorch: {torch.__version__}")
print(f"TensorFlow: {tf.__version__}")
print(f"NumPy: {np.__version__}")
print(f"OpenCV: {cv2.__version__}")
print("Environment ready for AI for Beginners")
PY

```

## Troubleshooting Common Issues

### Slow downloads or timeouts

Add the `conda-forge` channel explicitly and prefer it for heavy packages:

```bash
conda config --add channels conda-forge
conda config --set channel_priority flexible

```

### CUDA/GPU not detected

The [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) installs CPU-only PyTorch by default. For GPU support, modify the file to include `pytorch-cuda` or install separately:

```bash
conda install pytorch torchvision torchtext torchdata pytorch-cuda=12.1 -c pytorch -c nvidia

```

### Conflicting Python versions

Force a specific Python version before creating the environment:

```yaml

# Add to environment.yml dependencies section

- python=3.11

```

Or create from a modified file:

```bash
conda env create --name ai4beg --file environment.yml python=3.11

```

## Related Setup Resources

- **[[`lessons/0-course-setup/setup.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/lessons/0-course-setup/setup.md)](https://github.com/microsoft/AI-For-Beginners/blob/main/lessons/0-course-setup/setup.md)** – Human-readable setup guide with alternatives (Docker, manual pip)
- **[[`lessons/0-course-setup/how-to-run.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/lessons/0-course-setup/how-to-run.md)](https://github.com/microsoft/AI-For-Beginners/blob/main/lessons/0-course-setup/how-to-run.md)** – Jupyter vs. VS Code launch instructions
- **[[`etc/quiz-app/README.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/etc/quiz-app/README.md)](https://github.com/microsoft/AI-For-Beginners/blob/main/etc/quiz-app/README.md)** – Running the Vue.js quiz application (uses same Python backend)
- **[[`requirements.txt`](https://github.com/microsoft/AI-For-Beginners/blob/main/requirements.txt)](https://github.com/microsoft/AI-For-Beginners/blob/main/requirements.txt)** – PyPI dependencies referenced by [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml)

## Summary

- **Clone** the microsoft/AI-For-Beginners repository to obtain [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml)
- **Create** the environment with `conda env create --name ai4beg --file environment.yml`
- **Activate** with `conda activate ai4beg` before any work session
- **Verify** with Python imports to confirm PyTorch and TensorFlow versions
- The YAML channels (`defaults`, `conda-forge`, `pytorch`) and version pins ensure reproducible, conflict-free dependency resolution

## Frequently Asked Questions

### Can I use pip instead of Conda for AI for Beginners?

Yes, but Conda is strongly recommended. The [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) handles compiled dependencies like OpenCV and MKL-optimized NumPy that often fail with pure-pip installs. If you must use pip, install the requirements in [[`requirements.txt`](https://github.com/microsoft/AI-For-Beginners/blob/main/requirements.txt)](https://github.com/microsoft/AI-For-Beginners/blob/main/requirements.txt) and manually resolve OpenCV and Jupyter kernel registration.

### How do I update the environment when the curriculum changes?

Run `conda env update --name ai4beg --file environment.yml --prune` to sync with upstream changes. The `--prune` flag removes packages no longer listed. For major version bumps, it's safer to `conda env remove --name ai4beg` and recreate from scratch.

### Does the environment support GPU training?

The base [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) installs CPU-only PyTorch to maximize compatibility. For NVIDIA GPU support, modify the file to include `pytorch-cuda` or install GPU-enabled PyTorch after environment creation using the `pytorch` and `nvidia` channels. The curriculum's notebooks will automatically use CUDA if available.