Failed to import pytorch fbgemm.dll or one of its dependencies is missing

I have created a virtual environment using
python -m venv .
I don’t have a Cuda GPU, so I selected the CPU option from the installation which was:
pip3 install torch torchvision torchaudio

when I tried to import torch I got the below error:

(ali) C:\Users\pc\ali>python
Python 3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import torch
Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\pc\ali\Lib\site-packages\torch_init_.py”, line 141, in
raise err
OSError: [WinError 126] The specified module could not be found. Error loading “C:\Users\pc\ali\Lib\site-packages\torch\lib\fbgemm.dll” or one of its dependencies.

So I did this:
pip uninstall torch
and then tried from online resources the following:
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
and still the same problem happens.

It is probably worth mentioning, I checked that fbgemm.dll is actually there and so it is probably one of its dependencies that is missing. I tried viewing them (on my friends machine where the installation worked with no issues) in Dependency walker and here is the photo I found on his:

from googling these seems to be MSVC/C++ runtime dependencies? is it required that I install some C++ stuff?

1 Like

I had the same issue with fbgemm.dll when trying to run a ComfyUI session after following comflowy CLI procedure for installation, when invoking python main.py

Thank you for mentioning the idea of checking for fbgemm.dll with dedicated tool, this unlocked my situation but dependency walker dates back 2006, since then dll have changed and a more modern tool is required, found lucasg dependencies. This latest tool shows only one missing dependency to fbgemm.dll in my windows setup and that was libomp140.x86_64.dll

Since it is distributed with visual studio (not visual studio code) I installed visual studio community edition and libomp140.x86_64.dll was now put in both the visual studio program files and in C:\Windows\System32\ ie. in the Path. Now the ComfyUI main.py script runs fine on my system. Hope this helps.

install VC_redist.X64 - 14.29.30153 it will solve the fbgemm.dll problem.