pytorch之安装踩坑

Conda换源

1.清华源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/

# 设置搜索时显示通道地址
conda config --set show_channel_urls yes
#添加pytorch的镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

2.中科大源

conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
conda config --set show_channel_urls yes

在windows下打开Anaconda Prompt中输入上面代码即可添加国内源。如图演示:

这一步影响后面安装的舒服程度。在Linux环境下,可以将上述配置写在配置文件~/.condarc中,如:

channels:
- https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
- https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- defaults
show_channel_urls: true

conda正式安装

  1. conda create --name pytorch python=3.6
  2. conda install pytorch torchvision cudatoolkit=10.0

我倾向于根据框架创建不同的虚拟环境,创建好之后。
conda activate pytorch #激活环境
conda deactivate pytorch #退出环境

激活完成之后,命令行左边小括号中已经变成新环境的名字。这时候就可以去Pytorch官网查找自己适合的Pytorch。


复制conda install 代码,记得去掉-c pytorch,这样才会使用刚刚换了的国内源下载。
按照提示安装,最后显示安装完成后。使用命令行测试是否安装成功,如下图:

CUDA 安装#

这一步主要需要先检查本机显卡的cuda信息及适配cuda-sdk版本

  1. 右击桌面->nvidia控制版本->"帮助"->"系统信息“
  2. 这里有”显示“,主要记录了本显卡的cuda核心数,显存的大小,带宽等等
  3. ”组件“,主要记录了本显卡的cuda的各个组件的版本。
  4. ”组件“里面有一个nvcuda.dll的文件,查看它右侧的版本号,对应的我们就要下载cuda sdk的版本。
  5. cuda sdk的各个版本下载地址:https://developer.nvidia.com/cuda-toolkit-archive
  6. cudnn安装在官网依照要求(要注册)下载压缩包,解压之后复制bin文件夹中的.dll文件到CUDA安装目录下:

检查

NVIDIA-SMI

在windows下:
1.cd C:\Program Files\NVIDIA Corporation\NVSMI
2.nvidia-smi
在linux下:
nvidia-smi

Pytorch

在命令行测试如下图:

参考

https://www.cnblogs.com/litifeng/p/9094053.html

posted on 2019-07-08 22:49  20189214李熹桥  阅读(318)  评论(0编辑  收藏  举报

导航