# How to Update the Conda Environment for AI for Beginners

> Update your AI For Beginners conda environment using environment.yml. Refresh AI4beg with the latest curriculum dependencies by running conda env update prune.

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

---

**Run `conda env update -f environment.yml --prune` after pulling the latest changes to refresh the pre-defined `ai4beg` environment with the newest curriculum dependencies.**

The Microsoft `AI-For-Beginners` repository ships with a pre-configured **Conda environment** named `ai4beg` that bundles every Python package required for the course notebooks and labs. Keeping this environment current ensures that core libraries such as TensorFlow, PyTorch, and Keras remain aligned with the latest lesson code. Learning how to update the conda environment for AI for Beginners is essential for avoiding dependency conflicts when the curriculum changes.

## Pull the Latest Curriculum Changes

Before updating any packages, synchronize your local copy of the repository so you have the most recent [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) definition. Microsoft maintains this file at the repository root to declare exact package versions and new dependencies added to the curriculum.

Run the following command from your local clone:

```bash
git pull origin main

```

If you have not cloned the repository yet, download it from `microsoft/AI-For-Beginners` and `cd` into the project folder before proceeding.

## Update or Create the AI4Beg Conda Environment

The curriculum defines its dependency graph in [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml), which lists packages including **TensorFlow**, **PyTorch**, **Keras**, **OpenCV**, and supporting utilities. Choose the command that matches your current setup.

Use the first command if the `ai4beg` environment already exists on your machine:

```bash
conda env update -f environment.yml --prune

```

The `--prune` flag is critical because it uninstalls dependencies that are no longer listed in [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml), preventing version bloat.

Use the second command only if you are building the environment for the first time:

```bash
conda env create -f environment.yml

```

This command builds the `ai4beg` environment from scratch according to the exact specification in the Microsoft source code.

## Activate and Verify the Environment

Once the update completes, activate the environment and validate that the primary machine-learning frameworks are importable.

Run the following to activate the environment:

```bash
conda activate ai4beg

```

Verify the installation by listing packages and checking framework versions:

```bash
conda list
python -c "import tensorflow as tf; print(tf.__version__)"
python -c "import torch; print(torch.__version__)"

```

Successful output confirms that the updated conda environment for AI for Beginners contains all core libraries required by the lessons documented in [`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).

## Add Optional Dependencies for GPU Support

The base [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) covers CPU-based workflows, but you can extend the environment with GPU-specific tooling while the `ai4beg` environment is active.

For NVIDIA GPU support, install the CUDA toolkit from the Conda-Forge channel:

```bash
conda install -c conda-forge cuda-toolkit

```

You can also use **pip** to install packages that are unavailable through Conda:

```bash
pip install transformers

```

These extras are optional and depend on your local hardware and the specific notebooks you intend to run.

## Summary

- Synchronize your local repository with `git pull origin main` to fetch the latest [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) from the Microsoft `AI-For-Beginners` source code.
- Use `conda env update -f environment.yml --prune` to refresh an existing `ai4beg` environment, or `conda env create -f environment.yml` to build it for the first time.
- Always activate the environment with `conda activate ai4beg` before running lesson notebooks.
- Verify TensorFlow and PyTorch installations with quick Python import checks.
- Update the conda environment for AI for Beginners regularly to avoid dependency conflicts when lesson requirements change.

## Frequently Asked Questions

### How do I know if my conda environment is out of date?

If you encounter `ModuleNotFoundError` or version-mismatch warnings when opening notebooks from the Microsoft `AI-For-Beginners` repository, your `ai4beg` environment is likely stale. Compare your locally installed packages against the current [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) in the repository root, or simply run `conda env update -f environment.yml --prune` to force synchronization.

### What is the difference between `conda env update` and `conda env create`?

Use `conda env create -f environment.yml` only the first time you build the `ai4beg` environment. For all subsequent updates, use `conda env update -f environment.yml --prune` as implemented in the `microsoft/AI-For-Beginners` workflow; the update command modifies the existing environment and the `--prune` flag removes packages that are no longer required by the curriculum.

### Can I add extra packages to the ai4beg environment without breaking the curriculum?

Yes. You can safely install supplementary libraries—such as `transformers` via pip or `cuda-toolkit` via Conda-Forge—while the `ai4beg` environment is active. Just avoid upgrading existing pinned packages like TensorFlow or PyTorch unless the official [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) changes, since the lessons are tested against specific versions listed in that file.

### Where can I find the official setup instructions for the course?

The definitive setup guide lives in [`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) inside the `microsoft/AI-For-Beginners` repository. The repository also summarizes quick-start commands in the Setup section of [`README.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/README.md). Both documents reference the root-level [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) file used to provision the Conda environment.