Windows Conda 安装Pytorch的小坑
本文最后更新于 2025-01-24,文章内容可能已经过时。
有很长一段时间没有在Windows上配置过环境了,之前没有记录,导致这次配置时出了点小问题。
安装Pytorch
注意安装Pytorch如果是gpu版本不要使用pip清华源,清华源只有cpu版本
笔者使用官网的conda安装方式:
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
import torch failed
在conda list
中我找到了pytorch
,但是使用jupyter
时却无法import
随后我在命令行尝试了python3
和python
导入torch
,便发现了端倪
使用python
命令可以导入,而使用python3
命令不能导入,jupyter
默认使用python3
运行,那么问题在这里了
我们可以看到python3
只有系统默认的解释器,没有conda
环境的,于是我们找到conda
环境python
解释器的位置D:\softwares\conda\envs\torch\python.exe
,将其复制一个副本并重命名为python3.exe
,此时我们在conda
中执行python3
,用的便是这个安装了torch
的解释器
在jupyter中使用conda环境
在jupyter
中我们还需要导入ipykernel
conda activate torch
pip install ipykernel -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
python -m ipykernel install --name torch
jupyter notebook
那让我们在jupyter
中测试一下:
- 感谢你赐予我前进的力量
赞赏者名单
因为你们的支持让我意识到写文章的价值🙏
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 Moon
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果