安装pytorch时版本冲突问题

使用conda指令安装超时间等待不超过,故而选择使用pip配合国内镜像下载

激活对应的conda虚拟环境,在管理员权限下终端输入:

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 -i https://pypi.tuna.tsinghua.edu.cn/simple

指令由 官网生成的pip指令+ -i https://pypi.tuna.tsinghua.edu.cn/simple指定清华源

注意:直接使用pip安装可能会出现torch版本和cuda不匹配的问题

可以通过以下代码查看
import torch
import torchvision
print('torch.__version__:',torch.__version__)  #查看torch版本
print('torchvision.__version__:',torchvision.__version__)  #查看torchvision
print('gpu:',torch.cuda.is_available()) #查看gpu版本是否可用

官网的下载指令安装的torch与torchvision版本可能不匹配,根据torchvision官网查询到的torch版本找到对应的torchvision版本到download官网地址中下载。

torch torchvision python
main / nightly main / nightly >=3.8, <=3.10
1.13.0 0.14.0 >=3.7.2, <=3.10
1.12.0 0.13.0 >=3.7, <=3.10
1.11.0 0.12.0 >=3.7, <=3.10
1.10.2 0.11.3 >=3.6, <=3.9
1.10.1 0.11.2 >=3.6, <=3.9
1.10.0 0.11.1 >=3.6, <=3.9
1.9.1 0.10.1 >=3.6, <=3.9
1.9.0 0.10.0 >=3.6, <=3.9
1.8.2 0.9.2 >=3.6, <=3.9
1.8.1 0.9.1 >=3.6, <=3.9
1.8.0 0.9.0 >=3.6, <=3.9
1.7.1 0.8.2 >=3.6, <=3.9
1.7.0 0.8.1 >=3.6, <=3.8
1.7.0 0.8.0 >=3.6, <=3.8
1.6.0 0.7.0 >=3.6, <=3.8
1.5.1 0.6.1 >=3.5, <=3.8
1.5.0 0.6.0 >=3.5, <=3.8
1.4.0 0.5.0 ==2.7, >=3.5, <=3.8
1.3.1 0.4.2 ==2.7, >=3.5, <=3.7
1.3.0 0.4.1 ==2.7, >=3.5, <=3.7
1.2.0 0.4.0 ==2.7, >=3.5, <=3.7
1.1.0 0.3.0 ==2.7, >=3.5, <=3.7
<=1.0.1 0.2.2 ==2.7, >=3.5, <=3.7

下载完成会得到一个whl文件,进入目录激活conda环境,pip install 文件名.whl

你可能感兴趣的:(pytorch,人工智能,python)