import torch: How to fix OSError WinError 126, error loading fbgemm.dll or dependencies [duplicate]
Asked Answered
N

8

8

I installed the modules below:

conda install pytorch==2.2.0 torchvision==0.17.0 torchaudio==2.2.0 -c pytorch

Then installed numpy, pandas, matplotlib, seaborn, sickit-learn, pyedflib in this environment. Yet upon import it seems some files are missing:

OSError                                   Traceback (most recent call last)
Cell In[3], line 1
----> 1 import torch
      2 from torch import nn
      3 import numpy as np

File d:\anaconda3\envs\RN\lib\site-packages\torch\__init__.py:141
    139                 err = ctypes.WinError(ctypes.get_last_error())
    140                 err.strerror += f' Error loading "{dll}" or one of its dependencies.'
--> 141                 raise err
    143     kernel32.SetErrorMode(prev_error_mode)
    146 def _preload_cuda_deps(lib_folder, lib_name):

OSError: [WinError 126] can't find this module. Error loading "d:\anaconda3\envs\RN\lib\site-packages\torch\lib\fbgemm.dll" or one of its dependencies.

I reinstalled torch, but I can't solve it. And I even checked the file 'fbgemm.dll', it is there.

Narcolepsy answered 6/3, 2024 at 12:32 Comment(4)
oh I solve this problem. thank you for your help. When I check a new environment there has differences about whether files are. So I remove some files that are not in new environment, then it can work.Narcolepsy
you manually removed files from the base environment to keep working in it? If I got it right, better use the new env instead. Otherwise it might create problems later?Cartercarteret
because this looks like a problem others might have i went ahead and edited your post. It's be great if you would take the time to review my edit, especially you install lineCartercarteret
For anyone having the same issue, I found a simple fix by getting a missing dll: #78484797Aflutter
M
32

I've faced this problem and reinstalled pytorch and installed VC_Redist after trying many methods but all failed to run Pytorch properly.

But the issue solved by simply downloading libomp140.x86_64.dll and place it in 'C:\Windows\System32' and it finally works after long pain of trying this and that!

Melleta answered 6/8, 2024 at 11:43 Comment(4)
I encountered this on fresh install of SD.Next and this worked for me, but I'd really like a better solution than copying random dll off internet to my System32.Schaller
This seems to be where this idea comes from: stackoverflow.com/a/78798424. I would not download from that site for security reasons.Isiahisiahi
Doing this fixed my problem immediately. When I ran this command: python -c "import torch; print(torch.version.cuda); print(torch.cuda.is_available()); print(\"Number of GPUs: \", torch.cuda.device_count())" The correct output I expected was: 11.8 True Number of GPUs: 1Narthex
Idk, I did that, and it didn't work. I reinstalled everything, refreshed everything, updated everything, no fix.Kelcey
P
6

I was also facing the same issue. But the issue got resolved when I uninstalled torch 2.4.0 and installed torch 2.3.1. The issue is because of compatibility.

Phylys answered 14/8, 2024 at 8:14 Comment(2)
Just adding the versions that worked for me: torch==2.3.1 torchaudio==2.3.1 torchvision==0.18.1Impeditive
This fixed the issue for me, and this feels way safer than downloading some unknown dll from an unknown site, this should be the preferred solutionRaffinose
S
1

I encountered this problem when installing torch 2.4.0, but pip told me that torchvision 0.18.1 is incompatible with 2.4.0. So I uninstall 2.4.0 and install torch 2.3.1 , the problem disappeared.

Sibley answered 11/8, 2024 at 4:5 Comment(0)
C
0

It looks like, somehow, another file is missing (one of its dependencies). Starting from a new environment could remove unnecessary constraints. Inspired from this answer, with all requirements at once, not one part then add the other modules:

conda create -n env_torch pytorch=2.2.0 torchvision=0.17.0 torchaudio=2.2.0 numpy pandas matplotlib seaborn scikit-learn pyedflib
activate env_torch 

The conda cheat sheet is your best friend. Other things I looked up:

Cartercarteret answered 7/3, 2024 at 13:9 Comment(0)
E
0

I had the fbgemm.dll or one of its dependencies is missing error, and I just fixed it. I tried the vc_redist reinstallation, downloading vscommunity, and nothing worked.

What worked for me is this:

  1. Install miniconda
  2. Add the folder miniconda and miniconda/Scripts to the user PATH
  3. Check your python version // In my case 3.12.2
  4. conda create -n my_environment python=3.12.2
  5. conda activate my_environment
  6. conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia //Because previusly I had installed https://developer.nvidia.com/cuda-11-8-0-download-archive
  7. conda install -c conda-forge librosa pandas numpy
  8. Then you make a testTorch.py to check if you can import torch

And it worked. I hope this helps you.

Epizoic answered 26/7, 2024 at 11:9 Comment(0)
F
0

Install this dll file and paste it into system32, that should work.

Then, go to cmd, type python, and hit Enter. Once you are in the Python shell, cross check with the commands:

>>> import torch
>>> print(torch.__version__)
//output
2.4.0+cpu
>>>
Fiester answered 7/8, 2024 at 8:52 Comment(1)
Never ever download a dll file from unknown sources and put in your system folders. You never know what might be lurking inside.Perplexity
C
0

I solved the problem by running the following command: pip3 install torch==2.3.1+cpu torchvision==0.18.1+cpu -f https://download.pytorch.org/whl/torch_stable.html

Containment answered 2/9, 2024 at 12:2 Comment(0)
S
0

I was also facing the same issue. but I downloaded and copy libomp140.x86_64.dll and paste to C:\Windows\System32 then it works properly.

Statecraft answered 3/9, 2024 at 12:26 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.