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.

3 Likes

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

3 Likes

Thanks, really useful!

Is that specific version required? coz i do have 14.40.33810 and same issue happens, i think libomp* is (no longer) shipped with it (?) and not very keen to downgrade it.

thanks,it is working

Thank you! It worked for me.

The world needs guy like you! Ty

where can i download this?

Thanks, frobnicat! The DLL fix worked perfectly!

https://www.microsoft.com/en-US/download/details.aspx?id=48145&lt

downloaded the latest version14.40.33810.0 from Microsoft site Latest supported Visual C++ Redistributable downloads | Microsoft Learn. It resolves the issue. many thanks.