Import torch 出错
报错:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'torch'
首先输入: exit() 退出python
再下载输入:
conda install pytorch torchvision torchaudio cpuonly -c pytorch
接下来出现:
…
…
…

下面:点击此处

出现:

其实env_pytorch 目录在这

下面进入对应env_pytorch 环境分别输入以下三句话:
conda install ipython
conda install jupyter
python -m ipykernel install --user --name pytorch
三步完成之后:

出现新的jupyter

点击打开

点击此网址进入网页

输入运行即可。

But:这里是实心的,不能运行


然后再输入:
pip insatll pyzmq==19.0.2
然后重新打开并新建,会变成空心的:

进入环境
输入:conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia

下载完成后,进入python 在输入import torch
!!!成功了!!!

文章描述了在Python环境中导入torch模块时遇到错误的情况,以及解决这个问题的步骤。用户首先尝试使用conda安装pytorch、torchvision和torchaudio,然后在特定环境中安装ipython、jupyter和pykernel。当jupyternotebook无法运行时,安装了pyzmq的特定版本。最后,成功安装了带CUDA支持的pytorch,并能正常导入torch。
3万+

被折叠的 条评论
为什么被折叠?



