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

username: AlanJohnstone
cooked: <p>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</p>
<p>conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia</p>
<p>Now I cannot import torch. I get the error:</p>
<p>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.</p>
<p>I have tried both in a Jupyter notebook and in the Spyder IDE.</p>
<p>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.</p>
<p>The offending dll (caffe2_nvrtc.dll) does seem to be in the file location specified.</p>
<p>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.</p>
<p>Can anyone point me in the correct direction</p>

username: magnus1973
cooked: <p>Hi, had the same problem.<br>
I managed to get it to work when opening Spyder and entered the following in the command promt</p>
<p>pip install torch torchvision --user</p>
<p>It may work,</p>
<p>Best of luck!<br>
/M</p>

username: magnus1973
cooked: <p>Hi again,<br>
open the conda terminal, enter the following:<br>
pip3 install torch==1.10.0+cu113 torchvision==0.11.1+cu113 torchaudio===0.10.0+cu113 -f <a href="https://download.pytorch.org/whl/cu113/torch_stable.html" rel="noopener nofollow ugc">https://download.pytorch.org/whl/cu113/torch_stable.html</a> --user</p>
<p>After successful installation, go back to Spyder and enter the following in  Spyder command promt:<br>
pip install torch torchvision --user</p>
<p>Restart kernel in spyder</p>
<p>Test with import torch in Spyder command promt</p>
<p>Kind regards<br>
Magnus</p>

username: AlanJohnstone
cooked: <p>I managed to get rund the problem by uninstalling Pytorch and then reloading</p>

username: AlanJohnstone
cooked: <p>Update. Although the system works the Jupyter kernel dies when using matplotlib.<br>
after Googling I found that<br>
import os<br>
os.environ[“KMP_DUPLICATE_LIB_OK”]=“TRUE”<br>
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.</p>
<p>alan</p>

username: a10k
cooked: <p>conda install -c anaconda cudatoolkit</p>
<p>This worked for me, more details about this solution here: <a href="https://github.com/alievk/avatarify-python/issues/116" class="inline-onebox" rel="noopener nofollow ugc">caffe2_nvrtc.dll not found · Issue #116 · alievk/avatarify-python · GitHub</a></p>

username: ptrblck
cooked: <p>Are you still seeing the same issue using the latest nightly binaries as it should be fixed now?</p>

username: tmsav
cooked: <p>This solution worked for me too!</p>
<p>Also, restarting Spyder kernel afterward</p>
<p>Thanks!</p>

username: dkleine
cooked: <p>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 <code>conda install -c anaconda cudatoolkit</code>.</p>
<p>MS Win 10 Home, Version 10.0.19045 Build 19045<br>
Python 3.9.13</p>

username: Andrey_Sizov
cooked: <p>This solution worked for me! Super!<br>
Thanks!</p>