# How to Run Jupyter Notebooks with PyTorch and TensorFlow Support in Microsoft AI-For-Beginners

> Easily run Jupyter notebooks with PyTorch and TensorFlow support. Clone the AI-For-Beginners repo, create the Conda environment, and launch Jupyter for a seamless experience.

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

---

**Clone the Microsoft AI-For-Beginners repository, create the Conda environment from [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml), activate it, and launch Jupyter to run notebooks with both PyTorch and TensorFlow pre-installed.**

The Microsoft AI-For-Beginners curriculum provides a complete, ready-to-use environment for learning artificial intelligence. Instead of manually installing deep learning libraries, you can run Jupyter notebooks with PyTorch and TensorFlow support using a single Conda environment definition that includes both frameworks, Keras, OpenCV, and other essential tools.

## Setting Up the Environment

The repository includes an [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) file at the root level that pins specific versions of all dependencies. This ensures reproducible results across different machines.

### Step 1: Clone the Repository

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

```

This downloads the full curriculum, including lesson notebooks, data files, and configuration files.

### Step 2: Create the Conda Environment

Run the following command to build the environment defined in [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml):

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

```

The environment specification includes:
- **PyTorch** (`pytorch::pytorch`)
- **TensorFlow 2.17.0** (`tensorflow==2.17.0`)
- **Keras**, **OpenCV**, **scikit-learn**, **matplotlib**, and **Jupyter**

According to the source code in [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml), the dependencies are curated to avoid version conflicts between PyTorch and TensorFlow.

### Step 3: Activate the Environment

```bash
conda activate ai4beg

```

Once activated, `python`, `torch`, and `tensorflow` become available in your shell and to Jupyter kernels.

### Step 4: Launch Jupyter

Choose between the classic interface or Jupyter Lab:

```bash

# Classic Notebook UI

jupyter notebook

# Modern Lab interface (recommended)

jupyter lab

```

The setup instructions in [`AGENTS.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/AGENTS.md) confirm that either interface works with the pre-configured kernel.

## Opening and Running Lesson Notebooks

Navigate to any lesson directory containing `.ipynb` files. The curriculum provides parallel PyTorch and TensorFlow implementations for many lessons.

### PyTorch Example: Convolutional Neural Networks

Open `lessons/4-ComputerVision/07-ConvNets/ConvNetsPyTorch.ipynb` in the Jupyter file browser. Typical first cells include:

```python
import torch
import torchvision
import matplotlib.pyplot as plt

```

Executing these cells confirms PyTorch is functional and will automatically use GPU acceleration if available.

### TensorFlow Example: Convolutional Neural Networks

Open `lessons/4-ComputerVision/07-ConvNets/ConvNetsTF.ipynb`. Standard imports are:

```python
import tensorflow as tf
import matplotlib.pyplot as plt

```

The `ConvNetsTF.ipynb` notebook demonstrates identical concepts using TensorFlow/Keras APIs.

## Verifying GPU Acceleration

If you have a CUDA-compatible GPU, the Conda packages will automatically detect and use it. Verify inside any notebook:

**For PyTorch:**

```python
import torch
print(torch.cuda.is_available())

```

**For TensorFlow:**

```python
import tensorflow as tf
print(tf.config.list_physical_devices('GPU'))

```

The troubleshooting guide in [`AGENTS.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/AGENTS.md) recommends these exact snippets for GPU detection. Both should return `True` or a non-empty list when CUDA drivers are properly installed.

## Quick Reference: Complete Setup Commands

```bash

# 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

# Launch Jupyter

jupyter lab

```

## Troubleshooting Common Issues

| Issue | Solution | Source |
|-------|----------|--------|
| Environment creation fails | Update Conda: `conda update conda -y` | [`AGENTS.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/AGENTS.md) troubleshooting |
| Jupyter kernel not found | Reinstall kernel: `python -m ipykernel install --user --name ai4beg` | [`AGENTS.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/AGENTS.md) |
| GPU not detected | Run `nvidia-smi` to verify drivers, then use GPU check code above | [`AGENTS.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/AGENTS.md) GPU section |
| Package conflicts | Ensure you use `conda env create` rather than `pip install` | [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) structure |

## Key Files in the Repository

- **[`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml)** — Conda environment definition containing PyTorch, TensorFlow, and dependencies
- **[`requirements.txt`](https://github.com/microsoft/AI-For-Beginners/blob/main/requirements.txt)** — Additional pip packages referenced by the Conda environment
- **[`AGENTS.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/AGENTS.md)** — Human-readable setup instructions and troubleshooting
- **`lessons/4-ComputerVision/07-ConvNets/ConvNetsPyTorch.ipynb`** — Example PyTorch notebook
- **`lessons/4-ComputerVision/07-ConvNets/ConvNetsTF.ipynb`** — Example TensorFlow notebook

## Summary

- **Clone** the Microsoft AI-For-Beginners repository from GitHub
- **Create** the Conda environment using [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) to get PyTorch, TensorFlow, and all dependencies in one command
- **Activate** with `conda activate ai4beg` and **launch** Jupyter with `jupyter lab`
- **Open** lesson notebooks in either PyTorch or TensorFlow variants and execute cells immediately
- **Verify** GPU availability with built-in checks if you have CUDA hardware

## Frequently Asked Questions

### Where are the PyTorch and TensorFlow notebooks located?

Many lessons include parallel implementations. For example, `lessons/4-ComputerVision/07-ConvNets/` contains both `ConvNetsPyTorch.ipynb` and `ConvNetsTF.ipynb`. Browse the `lessons/` directory to find corresponding versions for other topics.

### Do I need to install PyTorch and TensorFlow separately?

No. The [`environment.yml`](https://github.com/microsoft/AI-For-Beginners/blob/main/environment.yml) file in the repository root defines a complete environment including both frameworks, Keras, OpenCV, and Jupyter. Create the environment once and all libraries are ready to use.

### How do I know if my GPU is being used?

Run the verification code snippets from [`AGENTS.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/AGENTS.md) inside any notebook: `torch.cuda.is_available()` for PyTorch or `tf.config.list_physical_devices('GPU')` for TensorFlow. These return `True` or device lists when GPU acceleration is active.

### Can I use pip instead of Conda?

The project is designed for Conda to handle complex binary dependencies for PyTorch and TensorFlow. While [`requirements.txt`](https://github.com/microsoft/AI-For-Beginners/blob/main/requirements.txt) exists for supplementary packages, the recommended path is `conda env create --file environment.yml` to avoid version conflicts.