I cannot use the pytorch that was built successfully from source: (DLL) initialization routine failed. Error loading caffe2_detectron_ops_gpu.dll

Thank you very much for your fast answer @lorenzznerol (are you italian like me?),
I tried activating the base environment and it solves the warning in python but not the torch error.

C:\Users\AZand_000\Downloads\Pytorch\pytorch>conda activate base

(base) C:\Users\AZand_000\Downloads\Pytorch\pytorch>python
Python 3.8.5 (default, Sep  3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\AZand_000\Downloads\Pytorch\pytorch\torch\__init__.py", line 128, in <module>
    raise err
OSError: [WinError 126] Impossibile trovare il modulo specificato. Error loading "C:\Users\AZand_000\Downloads\Pytorch\pytorch\torch\lib\caffe2_detectron_ops_gpu.dll" or one of its dependencies.
>>>

After that I tried to activate myenv (that is my torch environment) but it dosen’t work anyway:

(myenv) C:\Users\AZand_000\Downloads\Pytorch\pytorch>conda activate base

(base) C:\Users\AZand_000\Downloads\Pytorch\pytorch>activate myenv

(myenv) C:\Users\AZand_000\Downloads\Pytorch\pytorch>python
Python 3.8.5 (default, Sep  3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\AZand_000\Downloads\Pytorch\pytorch\torch\__init__.py", line 128, in <module>
    raise err
OSError: [WinError 126] Impossibile trovare il modulo specificato. Error loading "C:\Users\AZand_000\Downloads\Pytorch\pytorch\torch\lib\caffe2_detectron_ops_gpu.dll" or one of its dependencies.

In my case it took me months to find out the solution, and even with the solution, it can still take some days with some bad luck. I would rather suggest having a workaround ready for the whole issue - simply install pytorch without cuda in a separate environment, just to start with, and use the nights to go on with the installation of pytorch with cuda. It is a risky path to try installing this under time pressure (I have missed my assignment due to this, proving that the worst case can actually happen ;).

Anyway, there is a good chance that you can solve the issue. You seem to not have followed the guide completely since that caffe2_detectron error was the first thing that was solved in this thread, see I cannot use the pytorch that was built successfully from source: (DLL) initialization routine failed. Error loading caffe2_detectron_ops_gpu.dll - #2 by peterjc123.

The solution for that in short: You need to add MKL as an installation from SOURCE as well. That is, you need to download the source code of MKL and use that in parallel to the source code installation of pytorch to fix that error. Please follow the steps which are summarized in one ordered overview on superuser, see the link at the bottom of I cannot use the pytorch that was built successfully from source: (DLL) initialization routine failed. Error loading caffe2_detectron_ops_gpu.dll - #20 by lorenzznerol.

I had the same issue, but looks like I’ve found easier solution. In my case I’ve just downgrade from

torch=1.7.1 

to

torch=1.6.0 

and the issue has gone.
Maybe it will help someone.

1 Like