# How to Run Jupyter Notebooks in VS Code with the Correct Python Kernel: A Complete Setup Guide

> Easily run Jupyter notebooks in VS Code using the AI-For-Beginners Conda environment. This guide simplifies Python kernel setup for seamless coding and experimentation.

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

---

**The AI-For-Beginners curriculum provides a pre-configured Conda environment that VS Code automatically detects and exposes as a Jupyter kernel, eliminating manual configuration.**

Running Jupyter notebooks in VS Code with the correct Python kernel ensures that all imports resolve and code executes as intended. For Microsoft's **AI-For-Beginners** repository, this means using the curriculum's custom Conda environment rather than your system Python. The following steps walk through cloning the repository, creating the environment, and selecting the proper kernel inside VS Code.

## Install Miniconda and Create the AI-For-Beginners Environment

Miniconda provides the `conda` package manager without the bloat of the full Anaconda distribution. The AI-For-Beginners repository includes an [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) file that pins exact package versions for reproducibility.

Run these commands to clone the repository and build the environment:

```bash
git clone https://github.com/microsoft/AI-For-Beginners
cd AI-For-Beginners
conda env create --name ai4beg --file .devcontainer/environment.yml
conda activate ai4beg

```

The `-f .devcontainer/environment.yml` flag points to the environment definition stored in the hidden `.devcontainer` directory, 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). This file specifies **TensorFlow 2.17**, the latest **PyTorch**, **NumPy 1.26**, and other dependencies required across all notebooks.

## Open the Repository in VS Code and Install Extensions

With the Conda environment activated, open the folder in VS Code:

```bash
code .

```

VS Code will prompt you to install the **Python Extension** if it is not already present. Accept this installation—it provides Jupyter notebook support and Conda environment detection. Once installed, VS Code automatically scans for Conda environments and registers `ai4beg` as an available Jupyter kernel.

If VS Code suggests "Reopen in Container," **decline this prompt**. Running locally with the Conda interpreter is faster for iterative notebook work, as noted in the official setup guide.

## Select the Correct Python Kernel in a Jupyter Notebook

Open any `.ipynb` file—for example, `lessons/5-NLP/13-TextRep/TextRepresentationPyTorch.ipynb`. In the top-right corner of the notebook interface, click the kernel selector. Choose **Python 3 (ai4beg)** from the dropdown list.

This selection connects the notebook to the interpreter located at `~/miniconda3/envs/ai4beg/bin/python` (or equivalent path on your system). The kernel metadata that VS Code generates looks like this:

```json
{
  "name": "Python 3 (ai4beg)",
  "language": "python",
  "display_name": "Python 3 (ai4beg)",
  "argv": [
    "/path/to/miniconda3/envs/ai4beg/bin/python",
    "-m",
    "ipykernel_launcher",
    "-f",
    "{connection_file}"
  ]
}

```

VS Code constructs this configuration automatically by reading Conda's `conda-meta` files—no manual kernel registration is required.

## Verify Your Environment Is Active

Run this test cell in any notebook to confirm the correct kernel is selected:

```python
import tensorflow as tf
import torch
import numpy as np

print(f"TensorFlow version: {tf.__version__}")  # Expected: 2.17.0

print(f"NumPy version: {np.__version__}")       # Expected: 1.26.x

print("All libraries loaded from the ai4beg environment!")

```

If these imports succeed and versions match, your Jupyter notebook in VS Code is using the correct Python kernel.

## Key Configuration Files in AI-For-Beginners

Understanding these source files helps troubleshoot environment issues:

- **[`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)** — The authoritative setup guide covering Conda, VS Code integration, and container vs. local trade-offs.

- **[`.devcontainer/environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/.devcontainer/environment.yml)** — The Conda environment definition with pinned package versions. This is the single source of truth for the curriculum's Python dependencies.

- **[`requirements.txt`](https://github.com/microsoft/AI-For-Beginners/blob/main/requirements.txt)** — Additional Python packages referenced from [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) for pip-managed dependencies.

## Summary

- **Clone** the AI-For-Beginners repository and **create the Conda environment** using [`.devcontainer/environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/.devcontainer/environment.yml).
- **Activate `ai4beg`** and open the folder in VS Code to trigger automatic environment detection.
- **Select Python 3 (ai4beg)** from the kernel picker in any notebook to run cells with curriculum-approved package versions.
- **Decline container prompts** to maintain fast local iteration with the Conda interpreter.

## Frequently Asked Questions

### Why does VS Code not show the ai4beg kernel in the picker?

VS Code's Python extension scans for Conda environments only after activation. Ensure you ran `conda activate ai4beg` before launching VS Code, or reload the window (`Developer: Reload Window`) after activation.

### Can I use a different Python version than what the curriculum specifies?

No. The [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) pins specific versions—such as TensorFlow 2.17 and NumPy 1.26—to prevent compatibility issues. Deviating from these versions may cause import errors or different behavior in notebook exercises.

### How do I update the environment if the repository changes?

Pull the latest changes, then run `conda env update -n ai4beg -f .devcontainer/environment.yml`. This applies any new package pins without recreating the environment from scratch.

### What if I prefer using Docker instead of Conda?

The repository includes Dev Container configuration, but the official [`how-to-run.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/how-to-run.md) recommends local Conda for faster notebook iteration. If you choose Docker, VS Code will handle kernel selection similarly, though startup times will be longer.