It’s a really big issue that we can’t use GPU inside our beloved VS-Code and have to use Google Collab instead.
It’s time to use your RTX 4060s (or whatever GPU you have) to full extent inside VS Code.
From my experience I did everything that should’ve worked (CUDA, cuDNN, Python 3.11, VS Code, conda env) and TensorFlow still ran on CPU.
This is a very common pain point:
TensorFlow pip wheels on native Windows (>= 2.11) are CPU-only
Even a perfect CUDA/cuDNN install will NOT make Windows TensorFlow use GPU.
So the official + recommended way:
- Run TensorFlow with GPU inside WSL2 Ubuntu
- Linux wheels include CUDA + cuDNN automatically
- Most ML/AI engineers on Windows use this setup
WSL = Windows Subsystem for Linux, an official Microsoft technology.
It allows you to run a full Linux system inside Windows without dual boot.
Think of it like:
- Running an Android app on Windows
- Running Linux commands inside Windows
- With direct GPU access for deep learning
SAFE? → Yes, used by millions.
Mess files? → No, Ubuntu is isolated.
wsl --install -d ubuntu-22.04What happens:
- Downloads Ubuntu 22.04
- Installs WSL2 backend
- Prepares Linux subsystem
If asked → Restart PC.
You’ll see:
Installing, this may take a few minutes...
Then it will ask:
Enter new UNIX username:
Pick any username & password.
nvidia-smiIf you see your RTX GPU → GPU works.
If not → driver issue.
Run all commands inside Ubuntu terminal.
sudo apt update && sudo apt upgrade -ysudo apt install -y python3 python3-venv python3-pip build-essentialpython3 -m venv ML-DL-latsource ML-DL-lat/bin/activateTo reactivate later:
source ~/ML-DL-lat/bin/activatepip install --upgrade pip setuptools wheelLinux wheels automatically include CUDA + cuDNN.
pip install "tensorflow[and-cuda]"pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121pip install numpy pandas scikit-learn scipy matplotlib seaborn tqdmpip install transformers datasets accelerate evaluate sentencepiecepip install opencv-python pillow imageiopip install jupyter jupyterlab ipywidgetspython - << 'PY'
import tensorflow as tf
print("TensorFlow:", tf.__version__)
print("Built with CUDA:", tf.test.is_built_with_cuda())
print("GPUs:", tf.config.list_physical_devices("GPU"))
PYExpected:
TensorFlow: 2.20.0
built_with_cuda: True
GPUs: [PhysicalDevice('/physical_device:GPU:0')]
PyTorch: 2.5.1+cu121
cuda: True
Device: NVIDIA GeForce RTX 4050 Laptop GPU
- TensorFlow GPU
- PyTorch GPU
- Full ML + DL stack
- CUDA working inside WSL
- Clean isolated environment
- Setup recommended by NVIDIA, Microsoft, Google
Check VS Code path:
Test-Path "$env:LOCALAPPDATA\Programs\Microsoft VS Code\Code.exe"
Test-Path "C:\Program Files\Microsoft VS Code\Code.exe"
Test-Path "C:\Program Files (x86)\Microsoft VS Code\Code.exe"Lets say correct path is:
$env:LOCALAPPDATA\Programs\Microsoft VS Code\Code.exe
Paste ALL of this in ADMIN PowerShell:
# Path to VS Code (confirmed)
$codePath = "$env:LOCALAPPDATA\Programs\Microsoft VS Code\Code.exe"
# 1) Create helper script in C:\Windows
$scriptPath = "C:\Windows\open-in-wsl.ps1"
$scriptContent = @'
param([string]$winPath)
if ([string]::IsNullOrEmpty($winPath)) {
$winPath = (Get-Location).ProviderPath
}
$winPath = $winPath.TrimEnd('\')
$drive = $winPath.Substring(0,1).ToLower()
$rest = $winPath.Substring(2).Replace("\","/")
$wslPath = "/mnt/$drive/$rest"
$codeExe = "$env:LOCALAPPDATA\Programs\Microsoft VS Code\Code.exe"
$folderUri = "vscode-remote://wsl+Ubuntu-22.04$wslPath"
Start-Process -FilePath $codeExe -ArgumentList "--folder-uri", $folderUri
'@
Set-Content -Path $scriptPath -Value $scriptContent -Encoding UTF8 -Force
Write-Host "Created script: $scriptPath"
reg add "HKCR\Directory\shell\OpenInWSL" /ve /d "Open in WSL (Ubuntu)" /f
reg add "HKCR\Directory\shell\OpenInWSL" /v Icon /d "$codePath" /f
$cmd = 'powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\Windows\open-in-wsl.ps1" "%V"'
reg add "HKCR\Directory\shell\OpenInWSL\command" /ve /d "$cmd" /f
Write-Host "*** Installed successfully! ***"reg add "HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}" /f
reg add "HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32" /ve /fRestart Explorer:
Stop-Process -Name explorer -ForceThen run:
explorer
Right click on the folder you want to open and select "open in WSL ubuntu" and open a new terminal in VS code
Activate environment:
source ~/ML-DL-lat/bin/activateInstall Jupyter kernel:
python -m ipykernel install --user --name ML-DL-lat --display-name "Python (ML-DL-lat)"Select kernel:
- Python (ML-DL-lat)
import tensorflow as tf
print(tf.__version__)
print(tf.config.list_physical_devices("GPU"))Expected:
['/physical_device:GPU:0']