import torch OSError: [WinError 127]

Viewed 5770

I'm trying to install torch-gpu. I have installed cuda 11.1 and installed torch via the command pip3 install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio===0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

It is so stupid but during the importing I have the following error OSError: [WinError 127] Error loading "C:\Users\User\AppData\Roaming\Python\Python38\site-packages\torch\lib\c10_cuda.dll" or one of its dependencies..

c10_cuda.dll exists in that directory, I spent several days and still can't solve it. I need torch-gpu and that's the point of using that possibility, please, do not comment 'install torch-cpu'.

1 Answers

Answering the question myself

To install torch-gpu one should:

  1. check the latest (or not) versions and compatible cuda version: https://pytorch.org/get-started/locally/, at this moment it is 11.1.

  2. download and install cuda of the established version in 1) step (https://developer.nvidia.com/cuda-toolkit-archive). That depends on the gpu, if any problems you may download older versions or maybe you have it installed? then you can check version manually in the command line: nvcc --version.

  3. install torch using commands as found in the 1) step (for instance conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c conda-forge)

  4. check the installation success as import torch torch.cuda.is_available().

In my case I had to delete previously installed torch pip uninstall torch and use conda clean -a for installation to end successfully.

Related