Cannot import torch on windows (dll problem)

Hello,
I am trying to install Pytorch from source (with CUDA). While the compilation was successful, I am having issues with importing torch on windows 10 (using an “old” GPU Quadro K5200). It prints the following error:

import torch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Installations\Pytorch\torch\__init__.py", line 139, in <module>
    raise err
OSError: [WinError 1114] Une routine d’initialisation d’une bibliothèque de liens dynamiques (DLL) a échoué. Error loading "C:\Installations\Pytorch\torch\lib\backend_with_compiler.dll" or one of its dependencies.

So, it appears to have a problem getting backend_with_compiler.dll or one of its dependencies.
Therefore, I was redirected to this website and I tried the command you provided. Gflags stops after trying to import the C:\WINDOWS\SYSTEM32\symsrv.dll, which is not on my machine. The last output lines are:

080c:3604 @ 276919921 - LdrLoadDll - ENTER: DLL name: C:\WINDOWS\SYSTEM32\symsrv.dll
080c:3604 @ 276919921 - LdrpLoadDllInternal - ENTER: DLL name: C:\WINDOWS\SYSTEM32\symsrv.dll
080c:3604 @ 276919921 - LdrpFindKnownDll - ENTER: DLL name: symsrv.dll
080c:3604 @ 276919921 - LdrpFindKnownDll - RETURN: Status: 0xc0000135
080c:3604 @ 276919921 - LdrpResolveDllName - ENTER: DLL name: C:\WINDOWS\SYSTEM32\symsrv.dll
080c:3604 @ 276919921 - LdrpResolveDllName - RETURN: Status: 0xc0000135
080c:3604 @ 276919921 - LdrpProcessWork - ERROR: Unable to load DLL: "C:\WINDOWS\SYSTEM32\symsrv.dll", Parent Module: "(null)", Status: 0xc0000135
080c:3604 @ 276919921 - LdrpLoadDllInternal - RETURN: Status: 0xc0000135
080c:3604 @ 276919921 - LdrLoadDll - RETURN: Status: 0xc0000135
(80c.3604): C++ EH exception - code e06d7363 (first chance)
080c:3604 @ 276920234 - LdrpGetProcedureAddress - INFO: Locating procedure "FlsGetValue" by name
(80c.3604): C++ EH exception - code e06d7363 (first chance)
(80c.3604): C++ EH exception - code e06d7363 (!!! second chance !!!)
quit:

What should I do to resolve this? Should I simply add it to the System32 folder? Or do I understand this wrongly?

I do not face this issue when installing pytorch (cpu only) via pip. But I want to have Pytorch with cuda.

I thank you in advance for your help

That error is misleading a bit, it should load even without symsrv.dll

Do you have visual studio ? If so:

  • run the gflags command as described in GitHub - peterjc123/pytorch_dll_load_smoketests: Dll load smoketests for PyTorch on Windows
  • run python.exe in console in the pytorch directory, leave it running
  • open Visual Studio as Administrator and Attach Process to the running python.exe
  • go to the running python.exe console, input “import torch” to let the DLL error show
  • in Visual Studio continue debugging, and check the Output Console, you’ll see there the real DLL loading issues