Pytorch import leads to libcudnn error

SimSim3097: <p>Hi,</p>
<p>I have been trying to install pytorch 2.6.0 in a new conda environment. I know pytorch install comes in with its own cuda bundle but the latest install I have been doing leads to following error when torch is imported.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/f/0/f07cd098193678b9b0ce96eecebafa317b8c68d7.png" data-download-href="https://discuss.pytorch.org/uploads/default/f07cd098193678b9b0ce96eecebafa317b8c68d7" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/f/0/f07cd098193678b9b0ce96eecebafa317b8c68d7_2_690x117.png" alt="image" data-base62-sha1="yjs0syklZS0ZBRijqZb1TfrEzaf" width="690" height="117" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/f/0/f07cd098193678b9b0ce96eecebafa317b8c68d7_2_690x117.png, https://discuss.pytorch.org/uploads/default/optimized/3X/f/0/f07cd098193678b9b0ce96eecebafa317b8c68d7_2_1035x175.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/f/0/f07cd098193678b9b0ce96eecebafa317b8c68d7.png 2x" data-dominant-color="262727"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1329×226 36.1 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>I can resolve this by installing cudnn and cuda toolkit via conda but usually that leads to an older version install of cudnn.</p>
<p>I was wondering if this is a bug that I am encountering or if there is any issues with the way I am doing the torch installation.</p>
<p>Thanks for your help!</p>

ptrblck: <p>Do you see the needed <code>nvidia</code> runtime libs in your pip environment and did the logs show these were installed?</p>

SimSim3097: <p>I did not notice cudnn in the conda environment after doing torch install so I ended up doing a conda install cudnn. Now, it does show the cudnn in the environment<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/e/b/ebcad2d2c398a2a25d490c9cb5bd23bf5f948838.png" data-download-href="https://discuss.pytorch.org/uploads/default/ebcad2d2c398a2a25d490c9cb5bd23bf5f948838" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/e/b/ebcad2d2c398a2a25d490c9cb5bd23bf5f948838_2_690x192.png" alt="image" data-base62-sha1="xDUKGnKdUP93jSVGV4CjM65oVkI" width="690" height="192" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/e/b/ebcad2d2c398a2a25d490c9cb5bd23bf5f948838_2_690x192.png, https://discuss.pytorch.org/uploads/default/original/3X/e/b/ebcad2d2c398a2a25d490c9cb5bd23bf5f948838.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/e/b/ebcad2d2c398a2a25d490c9cb5bd23bf5f948838.png 2x" data-dominant-color="272727"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">813×227 27.6 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
but I am getting the same error while importing torch.</p>

ptrblck: <p>Conda packages are not built anymore since PyTorch 2.6 as we are releasing pip wheels going forward. Did you install a PyTorch binary from <code>conda-forge</code>?</p>

SimSim3097: <p>Hi,</p>
<p>Thank you for your swift response. I did the original installation following the original command from pytorch website - pip3 install torch torchvision torchaudio. I selected Linux and CUDA 12.1 options.<br>
The only way the import error was resolved if I did conda install cudnn which installed an older version of cudnn8.x and downgraded the cudatoolkit to 11.x in my torch env. That seemed to work but I installed timm which re-installed torch and broke the environment, re-installing cudnn did not fix the issue.</p>
<p>After further investigating I stumbled across this thread <a href="https://github.com/pytorch/pytorch/issues/104259" class="inline-onebox" rel="noopener nofollow ugc">ImportError: libcudnn.so.8: cannot open shared object file: No such file or directory · Issue #104259 · pytorch/pytorch · GitHub</a> and tried the following solutions</p>
<ol>
<li>conda env config vars set LD_LIBRARY_PATH=&lt;your/path/to/missing/lib&gt;</li>
<li>sudo apt install cudnn</li>
</ol>
<p>Both did not work. I noticed I already had a libcudnn9.so file in my torch env but for some reason it was not detected. I tried setting the path to the system libcudnn9.so it did not work.<br>
sudo apt install cudnn did not work either.<br>
Finally, I downgraded the cudatoolkit selection on torch website for torch installation - pip3 install torch torchvision torchaudio --index-url <a href="https://download.pytorch.org/whl/cu118" rel="noopener nofollow ugc">https://download.pytorch.org/whl/cu118</a><br>
this seemed to work and for now I am able to import torch successfully in the env.<br>
I am wondering if there is an issue in the torch installatiion with cuda 12.1.</p>

ptrblck: <p>I don’t think the PyTorch wheel itself is broken and guess your environment might be. E.g. it doesn’t make sense to install an older cuDNN (version 8.x while PyTorch searches for 9.x) and CUDA (11.x instead of 12.x) to resolve any issues. I would recommend creating a new and empty virtual environment and installing PyTorch again there. If you see any issues, please let us know.</p>

SimSim3097: <p>Makes sense! I created a new env and installed torch2.6+cu11.8 that seems to fix it. Thanks for your help.</p>

ptrblck: <p>Great, thanks for confirming!</p>