# How to Run Jupyter Notebooks in VS Code with Conda Environments

> Learn to run Jupyter notebooks in VS Code using Conda environments. Set up the ai4beg environment and select your interpreter for seamless notebook execution with all dependencies.

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

---

**Create the `ai4beg` Conda environment from the repository's [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml), open the project in VS Code, and select the Conda interpreter to run all notebooks with their required dependencies.**

Running Jupyter notebooks in VS Code with a dedicated Conda environment gives you reproducible Python environments, IntelliSense, and integrated debugging for the Microsoft AI-For-Beginners curriculum. The repository provides an [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) that pins every dependency, and the [`how-to-run.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/how-to-run.md) guide documents the exact workflow for local execution.

## Installing Miniconda and Creating the Environment

The first step is installing **Miniconda**, a lightweight distribution that provides the `conda` package manager.

Once Miniconda is available, create the environment using the configuration in [`.devcontainer/environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/.devcontainer/environment.yml). This single file declares the `ai4beg` environment with Jupyter, the IPython kernel, TensorFlow, PyTorch, OpenCV, NumPy, and all AI libraries used across the lessons.

```bash

# Clone the repository

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

# Create the environment (this reads .devcontainer/environment.yml)

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

# Activate it

conda activate ai4beg

```

The [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) specifies Python 3.x plus pinned versions of scikit-learn, matplotlib, and other dependencies. Activating the environment puts these packages on your PATH without polluting your system Python.

## Configuring VS Code to Use the Conda Interpreter

With the environment activated, launch VS Code from the repository root:

```bash
code .

```

VS Code's Python extension will suggest itself when you open a `.py` or `.ipynb` file. Install it if prompted. Next, select the Conda interpreter:

1. Press `Ctrl+Shift+P` (or `Cmd+Shift+P` on macOS)
2. Type **"Python: Select Interpreter"**
3. Choose the `ai4beg` entry—VS Code detects Conda environments automatically and displays the full path

This binds the editor to the Conda environment's Python binary. The integrated Jupyter extension now launches kernels from `ai4beg`, ensuring every notebook cell executes with the curriculum's exact dependency versions.

> **Tip:** If VS Code prompts to *"Re-open in Container"*, decline this suggestion to stay with your local Conda installation as 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).

## Running a Jupyter Notebook

Open any notebook file—for example, `lessons/3-NeuralNetworks/03-Perceptron/Perceptron.ipynb`. VS Code renders the notebook natively. Click **"Run Cell"** or the play button beside any code cell.

The status bar shows the active kernel (e.g., `Python 3.10.12 ('ai4beg': conda)`). All imports resolve against the Conda environment's site-packages, and breakpoints in `.py` files hit correctly when debugging.

## Key Files in the Repository

| File | Purpose |
|------|---------|
| [`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) | Complete setup guide covering local Conda, Docker, and cloud options |
| [`.devcontainer/environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/.devcontainer/environment.yml) | Conda environment specification with all curriculum dependencies |
| `lessons/3-NeuralNetworks/03-Perceptron/Perceptron.ipynb` | Example notebook demonstrating the expected runtime environment |

## Troubleshooting Common Issues

### Kernel not found in VS Code

If the `ai4beg` kernel doesn't appear, ensure the environment is activated and run:

```bash
python -m ipykernel install --user --name ai4beg --display-name "Python (ai4beg)"

```

Restart VS Code and reselect the interpreter.

### Package import errors in notebooks

These indicate the notebook is running against a different Python installation. Check the kernel indicator in the top-right corner of the notebook panel. It must match your Conda environment name.

## Summary

- **Miniconda** provides isolated Python environments without conflicting system packages
- The [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) in [`.devcontainer/environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/.devcontainer/environment.yml) defines a reproducible `ai4beg` environment with all AI-For-Beginners dependencies
- VS Code's **Python: Select Interpreter** command binds notebooks to the Conda kernel
- Opening `.ipynb` files directly in VS Code gives you IntelliSense, variable inspection, and integrated debugging

## Frequently Asked Questions

### Do I need Docker to run the notebooks?

No. While the repository includes a Dev Container configuration for Docker users, the [`how-to-run.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/how-to-run.md) guide explicitly documents a local Conda workflow. Create the environment from [`.devcontainer/environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/.devcontainer/environment.yml), open VS Code, and decline the container prompt.

### Can I use an existing Conda installation instead of Miniconda?

Yes. Any Conda distribution (Anaconda, Miniforge, or existing Miniconda) works. The critical step is running `conda env create` with the provided [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) to ensure dependency alignment.

### Why does VS Code show multiple Python interpreters?

VS Code scans for system Python, virtualenvs, and Conda environments. Select the one whose path contains `envs/ai4beg`—this guarantees you're using the curriculum's frozen dependency set rather than a potentially incompatible system installation.