Abstract

今天电脑系统重装了,借此记录一下环境配置,PyTorch分为CPU版和GPU版,CPU版本安装非常简单,用官方的命令即可安装,主要是GPU版本的安装需要注意PyTorch、CUDA、cuDNN、N卡驱动他们之间的版本依赖关系,安装方法分为下载源码安装和直接命令安装,这里为了方便我就只做命令安装的笔记,如果不能上外网需要自己准备VPN,为了确保命令能自动下载到安装文件,最好都在连接了VPN之后开始命令操作。

PyTorch对CUDA版本要求:

https://pytorch.org/get-started/locally/
https://pytorch.org/get-started/previous-versions/
image.png

CUDA版本对应的pytorch版本

win10 PyTorch深度学习环境配置 - 图2

CUDA版本对显卡驱动版本有要求,见如下链接:

https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html
image.png

cuDNN与CUDA版本关系

https://developer.nvidia.com/rdp/cudnn-download
image.png

NVIDIA 驱动程序下载:

https://www.nvidia.cn/Download/index.aspx?lang=cn
https://www.nvidia.cn/geforce/drivers/

NVIDIA 驱动版本:

image.png

CUDA版本选择

image.png

  • 根据CUDA对N卡版本要求,我的N卡版本为391.35,所以只能选择CUDA9.0/9.1,电脑有点过时了呀,古董了。
  • 根据CUDA9.0,我的电脑只能选择pytorch1.1.0,参见连接:https://pytorch.org/get-started/previous-versions/

image.png

开始安装

1、电脑版本确定

  • 解压缩cuDNN压缩包,复制里面的3个文件夹

image.png

  • 粘贴到CUDA安装目录:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0

image.png

  • 测试cuDNN是否安装成功
    1. cd C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\extras\demo_suite
    image.png
    1. bandwidthTest.exe # 运行测试文件 Result = PASS表示通过,否则会错误提示,需要去检查版本是否互相支持
    image.png
    1. deviceQuery.exe # 查看设备
    image.png

    6、PyTorch安装

1. Conda命令直接安装,需要VPN

各版本安装命令:https://pytorch.org/get-started/previous-versions/
image.png

  1. conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=9.0 -c pytorch # 执行安装命令
  • 提示错误,连接不到服务器,因为我没有开VPN

image.png

  • 开启VPN 重新执行命令

image.png

2.下载本地pip安装,没有VPN建议用此方法

PyTorch Get Startedhttps://pytorch.org/get-started/previous-versions/
image.png
根据下载地址:https://download.pytorch.org/whl/cu90/torch_stable.html
找到对应的版本pytorch==1.1.0 torchvision==0.3.0 ,cp37代表的是python3.7。下载到本地,我的保存地址:E:\MyCode\github\pytorch\pytorch_install

image.png

找不到pytorch工具包,因为当前环境中没有安装pytorch

image.png

用conda创建虚拟环境

image.png
把路径“Anaconda3/Library/bin ”下面的两个文件:libcrypto-1_1-x64.dll ;libssl-1_1-x64.dll,复制到路径“Anaconda3/DLLs”下。

重新运行命令,即可解决。

image.png

切换到虚拟环境,cd到pytorch安装包目录:pip install 安装

image.png

pycharm,切换到虚拟环境

image.png

重新运行,成功!

image.png