Error database

OSError: [WinError 126] Error loading fbgemm.dll or one of its dependencies

A Windows dependency of PyTorch 2.4.0's fbgemm.dll is missing on your machine. Upgrade PyTorch past 2.4.0, and install the Microsoft Visual C++ Redistributable.

The message you saw
OSError: [WinError 126] Error loading fbgemm.dll or one of its dependencies

By Updated

The error

Output
OSError: [WinError 126] The specified module could not be found. Error loading "C:\Users\you\venv\Lib\site-packages\torch\lib\fbgemm.dll" or one of its dependencies.

It appears at import torch, before any of your code runs.

What it means

Windows failed to load one of PyTorch's DLLs. The phrase "or one of its dependencies" is doing the heavy lifting: fbgemm.dll itself exists at that path — a library it depends on is missing from your system. Windows names the file it was trying to load, not the one actually absent, which makes this error famously misleading.

Why it happens

PyTorch 2.4.0's Windows build of fbgemm depended on an OpenMP runtime DLL (libomp140.x86_64.dll) that many Windows machines do not have. Fresh Windows installs, and machines without Visual Studio, hit it immediately. The packaging was corrected in 2.4.1. The same WinError 126 can also appear on any torch version when the Microsoft Visual C++ runtime is missing entirely.

How to fix it

1. Upgrade PyTorch — 2.4.0 specifically is the broken release.

bash
pip install -U torch torchvision torchaudio

Any current version bundles its dependencies correctly. This is the clean fix; prefer it over DLL surgery.

2. Install the Microsoft Visual C++ Redistributable. Download "Visual C++ Redistributable for Visual Studio 2015-2022" (x64) from Microsoft's site and run the installer, then restart the terminal. This supplies the standard runtime DLLs Python packages assume, and fixes the sibling cases of WinError 126 too.

3. Stuck on exactly 2.4.0? Pin one release away.

bash
pip install torch==2.4.1

4. If the error persists, check for a broken install.

bash
pip uninstall -y torch
pip cache purge
pip install torch

An interrupted download can leave a truncated DLL that produces the same message.

How to prevent it

On a fresh Windows machine, install the VC++ Redistributable before Python data-science work — half the compiled-package problems on Windows trace back to its absence. And avoid pinning brand-new x.y.0 releases of heavy native packages; the x.y.1 that follows often exists precisely because of platform issues like this one.