Cannot import torch Error loading ..\caffe2_nvrtc.dll"

I am on a Windows 10 64 bit system. Pytorch for cuda has been working successfully for some time. Today I tried to upgrade to the latest version of Pytorch (1.13) using

conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia

Now I cannot import torch. I get the error:

OSError: [WinError 126] The specified module could not be found. Error loading “C:\Users\alan\anaconda3\lib\site-packages\torch\lib\caffe2_nvrtc.dll” or one of its dependencies.

I have tried both in a Jupyter notebook and in the Spyder IDE.

I have tried completely removing Anaconda and reinstalling afresh and then reinstalling Pytorch with no success. I do not believe I have any other versions of python installed.

The offending dll (caffe2_nvrtc.dll) does seem to be in the file location specified.

I have found various similar problems reported but they all date back to 2020 or earlier and none of them seemed to have a satisfactory solution.

Can anyone point me in the correct direction

1 Like

Hi, had the same problem.
I managed to get it to work when opening Spyder and entered the following in the command promt

pip install torch torchvision --user

It may work,

Best of luck!
/M

Hi again,
open the conda terminal, enter the following:
pip3 install torch==1.10.0+cu113 torchvision==0.11.1+cu113 torchaudio===0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html --user

After successful installation, go back to Spyder and enter the following in Spyder command promt:
pip install torch torchvision --user

Restart kernel in spyder

Test with import torch in Spyder command promt

Kind regards
Magnus

I managed to get rund the problem by uninstalling Pytorch and then reloading

Update. Although the system works the Jupyter kernel dies when using matplotlib.
after Googling I found that
import os
os.environ[“KMP_DUPLICATE_LIB_OK”]=“TRUE”
resolves the problem but there clearly is something wrong which I understand is multiple copies of OpenMP runtime is linked. I think this must be a Pytorch issue.

alan

conda install -c anaconda cudatoolkit

This worked for me, more details about this solution here: caffe2_nvrtc.dll not found · Issue #116 · alievk/avatarify-python · GitHub

1 Like

Are you still seeing the same issue using the latest nightly binaries as it should be fixed now?

This solution worked for me too!

Also, restarting Spyder kernel afterward

Thanks!

Today, I have updated CUDA from 11.8 to 12.1 and updated the cuDNN files from 11.x to 12.x and had the same issue with the latest stable build (1.13.1). Could fix it too with above mentioned solution using conda install -c anaconda cudatoolkit.

MS Win 10 Home, Version 10.0.19045 Build 19045
Python 3.9.13

This solution worked for me! Super!
Thanks!