简体   繁体   English

ModuleNotFoundError:没有名为“torch”的模块

[英]ModuleNotFoundError: No module named 'torch'

I try to use pytorch module by conda but I get an error我尝试通过 conda 使用 pytorch 模块,但出现错误

Traceback (most recent call last):
File "train.py", line 8, in <module>
import torch
ModuleNotFoundError: No module named 'torch'

when I write conda list | findstr torch当我写conda list | findstr torch conda list | findstr torch I see that torch is installed: conda list | findstr torch我看到火炬已安装:

在此处输入图像描述 What is the problem?问题是什么?

I tried:我试过:

conda update conda -n root
conda install mkl=2018

but get:但得到:

Collecting package metadata (current_repodata.json): done
Solving environment: done

# All requested packages already installed.

Could Not Find C:\WINDOWS\TEMP\conda-23721-26470.tmp
Could Not Find C:\WINDOWS\TEMP\tmpry_dlvar.bat

and the same error occurrence和同样的错误发生

Try the below mentioned one, surely it will work.尝试下面提到的一个,肯定会起作用。

conda install -c pytorch pytorch康达安装-c pytorch pytorch

This worked for me这对我有用

conda install pytorch torchvision -c pytorch

Try to run the following on the local environment as given in the pytorch website during installation.安装时尝试在pytorch官网给出的本地环境中运行以下命令。 Open Jupyter Notebook locally and run the following在本地打开 Jupyter Notebook 并运行以下命令

from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)

if this works then most likely the environment variable is not set properly.如果这有效,那么很可能是环境变量设置不正确。 I hope this helps.我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Conda - ModuleNotFoundError:没有名为“火炬”的模块 - Conda - ModuleNotFoundError: No module named 'torch' 导入火炬 ModuleNotFoundError: 没有名为“火炬”的模块 - import torch ModuleNotFoundError: No module named 'torch' ModuleNotFoundError: 没有名为“torch_scope”的模块 - ModuleNotFoundError: No module named 'torch_scope' ModuleNotFoundError:没有名为“torch.utils.serialization”的模块 - ModuleNotFoundError: No module named 'torch.utils.serialization' ModuleNotFoundError:没有名为“torch.utils.benchmark”的模块 - ModuleNotFoundError: No module named 'torch.utils.benchmark' ModuleNotFoundError:没有名为“torch”的模块(仅限 vscode) - ModuleNotFoundError: No module named 'torch'(on vscode only) 问题 ModuleNotFoundError: 没有名为“torch._C”的模块 - Problem ModuleNotFoundError: No module named 'torch._C' ModuleNotFoundError:没有名为“torch.nn”的模块; “火炬”不是 Mac OS 上的 package - ModuleNotFoundError: No module named 'torch.nn'; 'torch' is not a package on Mac OS 导入 torch.fx ModuleNotFoundError:没有名为“torch.fx”的模块 - import torch.fx ModuleNotFoundError: No module named 'torch.fx' Python PyTorch 错误:ModuleNotFoundError:没有名为“torch.utils.tensorboard”的模块 - Python PyTorch Error: ModuleNotFoundError: No module named 'torch.utils.tensorboard'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM