首页 > 解决方案 > 导入手电筒 OSError:[WinError 127]

问题描述

我正在尝试安装torch-gpu。我已经安装了 cuda 11.1 并通过命令安装了 torchpip3 install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio===0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

这太愚蠢了,但在导入过程中出现以下错误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在那个目录下,我搞了好几天还是解决不了。我需要torch-gpu,这就是使用这种可能性的关键,请不要评论“安装torch-cpu”。

标签: installationimporttorchoserror

解决方案


自己回答问题

要安装torch-gpu,应该:

  1. 检查最新(或不是)版本和兼容的 cuda 版本:https ://pytorch.org/get-started/locally/ ,此时它是 11.1。

  2. 在 1) 步骤 ( https://developer.nvidia.com/cuda-toolkit-archive )中下载并安装已建立版本的 cuda 。这取决于 gpu,如果有任何问题,您可能会下载旧版本或者您已经安装了它?然后您可以在命令行中手动检查版本:nvcc --version.

  3. 使用 1) 步骤中的命令安装 Torch(例如conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c conda-forge

  4. 检查安装成功为import torch torch.cuda.is_available().

就我而言,我必须删除以前安装的手电筒pip uninstall torchconda clean -a用于安装才能成功结束。


推荐阅读