How to Run Jupyter Notebooks in VS Code with Conda Environments

Create the ai4beg Conda environment from the repository's 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 that pins every dependency, and the 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. This single file declares the ai4beg environment with Jupyter, the IPython kernel, TensorFlow, PyTorch, OpenCV, NumPy, and all AI libraries used across the lessons.


# 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 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:

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.

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 Complete setup guide covering local Conda, Docker, and cloud options
.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:

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 in .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 guide explicitly documents a local Conda workflow. Create the environment from .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 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.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →