PyTorch in VS Code – Simple Step-by-Step Guide (2026)

Hey Arch! Here's a beginner-friendly guide to get PyTorch running in Visual Studio Code on Windows (Jacksonville vibes!). Takes 5–10 minutes.

  • Download from: https://code.visualstudio.com/
  • Install it — super straightforward, just click Next a few times.

  1. Open VS Code.
  2. Go to Extensions (Ctrl+Shift+X).
  3. Install these official Microsoft ones:
    • Python — essential
    • Jupyter — great for notebooks
    • Pylance (optional) — better autocompletion

  1. Open terminal in VS Code: Ctrl+` (backtick)
  2. Create virtual env (recommended):
    python -m venv pytorch-env
    pytorch-env\Scripts\activate
  3. Install PyTorch (check latest at pytorch.org):
    GPU (CUDA 12.x – if NVIDIA GPU):
    pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
    CPU only:
    pip install torch torchvision torchaudio

  • Ctrl+Shift+P → type "Python: Select Interpreter"
  • Choose .\pytorch-env\Scripts\python.exe

Create test_torch.py and paste:

import torch

print("PyTorch version:", torch.__version__)

x = torch.rand(5, 3)
print("Random tensor:\n", x)

if torch.cuda.is_available():
    print("CUDA/GPU is available! 🎉")
    print("Current GPU:", torch.cuda.get_device_name(0))
else:
    print("Running on CPU")

Right-click → Run Python File in Terminal. You should see a tensor and version info!

Jupyter in VS Code: Create .ipynb file → write & run PyTorch code cell-by-cell.

Common fixes:

  • "No module named torch"? → Wrong interpreter selected
  • GPU not working? → Run nvidia-smi in terminal
  • Slow? → Start with CPU version

Now dive into PyTorch tutorials — you're set! 🚀