How to Install Compatible PyTorch and TensorFlow Versions for AI for Beginners
Use the Conda environment from environment.yml to install TensorFlow 2.17.0, then add PyTorch 2.x separately to match your hardware for a conflict-free setup.
The AI for Beginners curriculum by Microsoft relies on both TensorFlow and PyTorch across its lesson notebooks. Because these libraries have complex binary dependencies and version sensitivities, understanding how to install compatible PyTorch and TensorFlow versions is essential before running any code from the repository.
Why Version Compatibility Matters
Deep learning frameworks depend on specific CUDA, cuDNN, and Python versions. Installing TensorFlow and PyTorch incorrectly leads to import errors, GPU detection failures, or silent numerical bugs.
In requirements.txt at the repository root, the Microsoft team pins TensorFlow 2.17.0 as the tested version:
tensorflow==2.17.0
PyTorch is not pinned in requirements.txt, but the lesson notebooks assume a PyTorch 2.x release compatible with Python ≥ 3.9. The recommended approach uses the provided Conda environment as a foundation, then adds PyTorch manually.
Method 1: Recommended Conda Environment Setup
The cleanest installation path uses environment.yml, which pins Python and core dependencies without bundling PyTorch.
Step 1: Create and Activate the Environment
conda env create -f environment.yml
conda activate ai4beg
This creates the ai4beg environment with TensorFlow 2.17.0 and all curriculum dependencies pre-installed.
Step 2: Install PyTorch for Your Hardware
CPU-only machines:
pip install torch==2.3.0
CUDA 12.1 GPU machines:
pip install torch==2.3.0+cu121 -f https://download.pytorch.org/whl/torch_stable.html
Other CUDA versions: Visit pytorch.org/get-started/locally and select your platform to generate the correct pip command.
Verify Your Installation
Confirm both libraries import correctly and detect your hardware:
import tensorflow as tf
import torch
print("TensorFlow:", tf.__version__) # Expected: 2.17.0
print("PyTorch:", torch.__version__) # Expected: 2.3.0 (or CUDA-specific tag)
# Test basic operations
tf_const = tf.constant([[1, 2], [3, 4]])
print("TF constant:\n", tf_const.numpy())
torch_tensor = torch.arange(0, 6).reshape(2, 3)
print("Torch tensor:\n", torch_tensor)
# GPU verification (skip if CPU-only)
print("TF GPU devices:", tf.config.list_physical_devices('GPU'))
print("Torch GPU available:", torch.cuda.is_available())
Run this verification script immediately after setup to catch environment issues before working through lessons.
Method 2: Pure pip Installation (Alternative)
If you prefer pip without Conda, install directly from requirements.txt then add PyTorch:
# Create virtual environment
python -m venv ai4beg-env
source ai4beg-env/bin/activate # On Windows: ai4beg-env\Scripts\activate
# Install pinned dependencies
pip install -r requirements.txt
# Add PyTorch (adjust for your CUDA version)
pip install torch==2.3.0
This method requires manual Python version management (3.9+ required) and offers less isolation than Conda.
Key Configuration Files in AI for Beginners
| File | Purpose |
|---|---|
requirements.txt |
Pins TensorFlow 2.17.0 and auxiliary packages like numpy, pandas, matplotlib |
environment.yml |
Defines the ai4beg Conda environment with Python version and channel configuration |
README.md |
Contains high-level setup instructions and links to getting-started guides |
Review these files in the microsoft/AI-For-Beginners repository to verify current version pins, as they may update between curriculum releases.
Troubleshooting Common Issues
ImportError: DLL load failed (Windows)
- Ensure Visual C++ redistributables are installed
- Use Conda rather than pip for automatic binary dependency resolution
CUDA out of memory / GPU not detected
- Verify
nvidia-smishows your GPU and CUDA version - Match PyTorch CUDA build to your system CUDA (e.g., cu121 for CUDA 12.1)
- TensorFlow 2.17.0 requires CUDA 12.2 and cuDNN 8.9 per official compatibility
Version conflicts between TensorFlow and PyTorch
- Always install TensorFlow first via
environment.ymlorrequirements.txt - Install PyTorch second with explicit version pinning
- Never mix Conda and pip installations for the same package
Summary
- TensorFlow 2.17.0 is the required version, pinned in
requirements.txt - PyTorch 2.3.0 (or latest 2.x) works reliably when added after TensorFlow setup
- Use the
environment.ymlConda workflow for clean dependency isolation - Always verify both frameworks import and detect GPU before running lesson notebooks
- Match CUDA versions carefully when using GPU acceleration
Frequently Asked Questions
Can I use newer TensorFlow versions than 2.17.0?
Microsoft tests the curriculum against TensorFlow 2.17.0 as specified in requirements.txt. Newer versions may work but are not validated—stick to 2.17.0 to avoid lesson-specific compatibility issues.
Why doesn't environment.yml include PyTorch?
The curriculum primarily uses TensorFlow, with PyTorch appearing in select lessons. Keeping PyTorch separate allows learners to install only the CPU or GPU variant matching their hardware, avoiding unnecessary large CUDA downloads.
How do I install PyTorch with ROCm for AMD GPUs?
AMD GPU support requires the ROCm build of PyTorch. Use: pip install torch==2.3.0+rocm5.7 -f https://download.pytorch.org/whl/torch_stable.html. Note that TensorFlow on AMD GPUs has limited support—you may need to run TensorFlow on CPU while using PyTorch on GPU.
What Python version does AI for Beginners require?
The environment.yml specifies Python 3.9 or newer. TensorFlow 2.17.0 and PyTorch 2.x both support Python 3.9–3.11. Avoid Python 3.12 unless you verify framework compatibility first.
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:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →