【软件安装篇】CUDA、cuDNN、Anaconda、pytorch安装详解以及下载安装时报错解决方法

一、验证电脑上的NVIDIA驱动是否安装成功。

在这里插入图片描述

二、安装CUDA

在这里插入图片描述
在这里插入图片描述

打开cmd窗口验证NVIDIA cuda是否安装成功(有的博客说需要安装后添加环境变量,我在添加环境变量之前验证是否安装成功,显示成功了,于是乎没有再添加其他的环境变量(我去系统变量里看了一下已经有了cuda的一些系统变量了))

在这里插入图片描述

三、安装cuDNN

在这里插入图片描述
在这里插入图片描述

四、安装Anaconda

安装Anaconda注意三点: 1、 选择all users模式

在这里插入图片描述

2、 选择安装位置

在这里插入图片描述

3、 勾选将路径添加到环境变量里

在这里插入图片描述

4、然后选择安装install即可

在这里插入图片描述

安装完之后给anaconda添加国内镜像配置。

打开cmd,输入以下命令:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

五、安装pytorch

创建名字为pytorch1.6,python版本为3.8的虚拟环境

conda create -n pytorch1.6 python=3.8

在这里插入图片描述

环境创建成功
在这里插入图片描述

Conda info -e  #查看现在拥有的环境

在这里插入图片描述

#激活pytorch1.6的环境
conda activate pytorch1.6

在这里插入图片描述

#在所创建的pytorch1.6环境下安装pytorch的1.6版本
conda install pytorch torchvision cudatoolkit=11.5 -c pytorch
#注意版本号对应

在这里插入图片描述

运行该条命令有错误,如下图。

在这里插入图片描述

一开始我以为是我的cuda版本不兼容了,后来百度发现不是这个原因。
把错误翻译过来就是说在当前这个渠道找不到这个包,那咱就换个渠道白,解决方法如下:
(参考文章链接:https://blog.csdn.net/ewba_gis_rs_er/article/details/84671406)
1、 在prompt中寻找可以安装的pytorch包的信息。

anaconda search -t conda pytorch

找到了一百多条,根据自己的系统选择合适的包。

在这里插入图片描述

2、 查看该包的下载信息。

anaconda show soumith/pytorch-cpu   #如果这个包不行就再换一个

在这里插入图片描述

3、 运行上图中红色标记的命令下载pytorch。
downloading…
下载完成,进入python中测试,输入命令import torch,此时没有反应就是最好的回应,恭喜你pythorch安装成功了。

在这里插入图片描述

另外,下载包的时候要把代理关了,否则就会报这个错误。
An HTTP error occurred when trying to retrieve this URL.
在这里插入图片描述

Guess you like

Origin blog.csdn.net/qq_45640219/article/details/121428503