无法导入Pytorch [WinError 126]找不到指定的模块 [英] Cannot import Pytorch [WinError 126] The specified module could not be found
问题描述
我正在尝试在Windows 10上进行Pytorch/Torchvision的基本安装和导入.我安装了Anaconda并创建了一个名为photo的新虚拟环境.我打开Anaconda提示符,激活环境,然后运行:
I'm trying to do a basic install and import of Pytorch/Torchvision on Windows 10. I installed a Anaconda and created a new virtual environment named photo. I opened Anaconda prompt, activated the environment, and I ran:
(photo) C:\Users\<user>\anaconda3\envs>conda install pytorch torchvision cudatoolkit=10.2 -c pytorch**
这成功安装了pytorch.运行 conda列表,我看到:
This installed pytorch successfully. Running conda list I see:
pytorch pytorch/win-64::pytorch-1.5.0-py3.7_cuda102_cudnn7_0
torchvision pytorch/win-64::torchvision-0.6.0-py37_cu102
然后在虚拟环境中打开python命令提示符,然后键入:
Then I open a python command prompt while in the virtual environment, and type:
import torch
打印以下错误:
回溯(最近通话最近): 文件",第1行,在 在第81行中输入文件"C:\ Users \ njord \ anaconda3 \ envs \ photo \ lib \ site-packages \ torch__init __.py" ctypes.CDLL(dll) init 中的文件"C:\ Users \ njord \ anaconda3 \ envs \ photo \ lib \ ctypes__init __.py",第364行 self._handle = _dlopen(self._name,mode) OSError:[WinError 126]找不到指定的模块
Traceback (most recent call last): File "", line 1, in File "C:\Users\njord\anaconda3\envs\photo\lib\site-packages\torch__init__.py", line 81, in ctypes.CDLL(dll) File "C:\Users\njord\anaconda3\envs\photo\lib\ctypes__init__.py", line 364, in init self._handle = _dlopen(self._name, mode) OSError: [WinError 126] The specified module could not be found
我已经卸载/重新安装了python和anaconda,但仍然遇到相同的问题.建议表示赞赏.
I have uninstalled/reinstalled python and anaconda but still run into the same issue. Advice appreciated.
推荐答案
请参阅以下链接: https://discuss.pytorch.org/t/cannot -import-torch-on-jupyter-notebook/79334
这很可能是因为您在未安装GPU驱动程序的系统上使用PyTorch的CUDA变体.也就是说,如果您没有Nvidia GPU卡,请根据 https:/上的命令安装仅cpu软件包./pytorch.org .
This is most probably because you are using a CUDA variant of PyTorch on a system that doesn’t have GPU driver installed. That is to say, if you don’t have a Nvidia GPU card, please install the cpu-only package according to the commands on https://pytorch.org.
conda安装pytorch torchvision cpuonly -c pytorch
conda install pytorch torchvision cpuonly -c pytorch
pip install torch == 1.5.0 + cpu torchvision == 0.6.0 + cpu -f https://download.pytorch.org/whl/torch_stable.html
pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
这篇关于无法导入Pytorch [WinError 126]找不到指定的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!