#超级系统详细#搭建深度学习环境(python3.8+cuda10.2+tensorflow2.3)

写在前面:

1、搭建环境前最重要的是先清楚各个版本之间的配对情况

官网版本匹配信息(tensorflow与python):https://tensorflow.google.cn/install/source_windows

大致如下:
cuda9–vs2017–tensorflow1–python3.7
cuda10–tensorflow2–python3.5及以上

这里由于已经安装的python是3.8的,所以选择 cuda10.2–tensorflow2.–python3.8–vs2017–cudnn8.0.2

2、 一定要先安装vs再安装cuda,不然vs找不到cuda项目,又要卸载重装cuda

2020.8.24更新:
1、下载whl文件进行python的第三方包安装的方法:
(1)将whl文件放到python的Script文件夹中,如图在这里插入图片描述

(2)在命令行中跳到python的Script文件夹中
(3)执行pip install 文件名
2、目前的tensorflow2只支持python3.8的64位,不支持32位(这也是为什么在本文第四节中会折腾这么久还是不行)

一、vs2017安装 ——

下载网址:https://my.visualstudio.com/Downloads?q=2015&pgroup=
1、登录账号
2、在搜索框中输入你想下载的版本,比如2017,vs往往会出现在最前面,这里选择社区版的就可以了,可以看到,还能对语言进行选择
在这里插入图片描述
3、下载好对应的文件后,点击运行(这里的图t-1是已经安装好社区版的,如果未安装好的都是“安装”按钮,没有“修改”和“启动”的按钮)然后就可以点击“安装”按钮,就会进入选择组件、语言包、安装位置的设置页面,如图t-2
在这里插入图片描述t-1

在这里插入图片描述
t-2

4、选择安装内容:
工作负载 – 使用C++的桌面开发
单个组件 – 不用理,后面会因为一些原因再逐个添加即可
语言包 – 随意
安装位置 – 随意,如果c盘内存不多,可以安装在d盘
在这里插入图片描述
5、等待安装完毕即可

二、cuda安装:
下载网址:
https://developer.nvidia.com/cuda-downloads
进入之后就可以去选择系统和版本在这里插入图片描述

1、运行exe,不需要改路径,因为cuda安装完后会自动删除对应文件夹,不会占内存
在这里插入图片描述
2、开始安装
在这里插入图片描述

(1) 选择自定义
在这里插入图片描述
(2) 只勾选第一个的部分(不太版本的cuda内容不一样)
在这里插入图片描述在这里插入图片描述

(3)安装位置 – 建议安装在d盘,如下面第二张图片在这里插入图片描述
在这里插入图片描述

(4)安装成功在这里插入图片描述

到这里可以选择运行Sample和Documentation在这里插入图片描述
3、查看安装是否成功 – 如果提示版本就成功了(但并不意味可以使用):nvcc -V
在这里插入图片描述

4、配置环境变量 – 添加红色框框里面的内容,其中第三个和第四个安装的时候自动添加了
在这里插入图片描述

CUDA_SDK_PATH = D:\CUDA\CUDA Samples
# 可以看到后面四个都是使用相对路径的
CUDA_SDK_LIB_PATH = %CUDA_SDK_PATH%\common\lib\x64
CUDA_SDK_BIN_PATH = %CUDA_SDK_PATH%\bin\win64
CUDA_LIB_PATH = %CUDA_PATH%\lib\x64
CUDA_BIN_PATH = %CUDA_PATH%\bin

再检查一下是否配置好:set cuda在这里插入图片描述

(5)启动deviceQuery.exe 和 bandwithTest.exe,验证是否配置成功:
cmd打开命令行界面,建议直接去到… \NVIDIA GPU Computing Toolkit\extras\demo_suite,在cmd,具体的路径要看你安装在哪里,我这里把cuda安装在D:\CUDA\

在这里插入图片描述
命令:deviceQuery.exe ;bandwidthTest.exe
如图:出现PASS这成功了
在这里插入图片描述
在这里插入图片描述

**三、cudnn:**下载网址:https://developer.nvidia.com/rdp/cudnn-download
需要登录,登录后点击I Agree To the Terms of the cuDNN Software License Agreement
同意即可显示出下载链接,对应的版本可以直接看,这里选择与cuda10.2对应的
1、解压压缩包
在这里插入图片描述
2、将三个文件夹(bin、include、lib)移动到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA
3、配置环境变量
就是刚刚移动到的目录和该目录下的lib->x64文件夹里面

四、安装tensorflow先要确定自己的python3.8是32位还是64位,因为tensorflow2.3.0只支持64位的;
①如果读者的python3.8是64位的话,可以直接pip install tensorflow就可以了,如果出现Read time out,可以去看https://blog.csdn.net/nihao_t/article/details/108163720。
②如果python3.8是32位的,读者可以直接跳到该节内容(第四节),去看第五节。(因为我一开始边安装边写的时候还不知道,所以折腾了半天)

#不可以直接用pip install tensorflow,会报错,如图
在这里插入图片描述
(1)下载文件
1、去官网下对应tensorflow – 特别慢,如果不是网络特别好都不建议
进入https://pypi.org/project/tensorflow/#files,输入tensorflow,选tensorflow2.3.0。然后点击download file找到符合你的版本的下载
在这里插入图片描述

在这里插入图片描述
2、使用清华源的来下载 – 一个字 - 》
https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/tensorflow/
注意选对应系统和python的来下载,我这里直接选最底下的了
在这里插入图片描述
(2)安装
cd跳到下载好的文件所在的文件夹,直接pip install 文件名
在这里插入图片描述
还是出错,令人绝望,不过还得再试
1、使用python -m pip debug --verbose来查看python3.8可以操作的文件格式(直接用import pip;print(pip.pep425tags.get_supported())是不可以的)-- 经过后面的折腾,主要是因为python是32位的,而tensorflow只支持64位的
在这里插入图片描述

2、改文件名,改成可以操作的:这里将tensorflow-2.3.0rc2-cp38-cp38-amd64.whl改成tensorflow-2.3.0rc2-cp38-cp38-win32.whl。(结果又报新错误,Read timed out,并且加上–default-timeout=100也一动不动,但也算前进了一步)
在这里插入图片描述
在这里插入图片描述
3、使用pip --default-timeout=100 install -U tensorflow-2.3.0rc2-cp38-cp38-win32.whl 命令来安装,核心是:pip --default-timeout=100 install -U ,特别是-U(不可以用–upgrade,用这个还是一样超时)

在这里插入图片描述
4、还是不行,漫长的等待与尝试,真的累。

在这里插入图片描述
5、突然问一下别人,想到是Read time out的问题,尝试换一下镜像:
pip --default-timeout=100 install -U tensorflow-2.3.0rc2-cp38-cp38-win32.whl -i https://pypi.douban.com/simple
居然就可以了在这里插入图片描述
然而在导入tensorflow包的时候,出错了,绝望,这个应该是因为python3.8是32位,最终只能放弃了在32位上挣扎了,找其他方法
在这里插入图片描述
6、找了很久,发现只能放弃使用python3.8的32位,但是想着卸载又重装很麻烦(而且看过一个帖子说尽量不要安装64位的python)。在别人的提醒下,决定使用Anaconda;

五、安装Anaconda,再在此基础上安装tensorflow
1、下载网址:https://www.anaconda.com/,下载安装包
在这里插入图片描述
在这里插入图片描述

2、运行下载好的程序
1、一路nex、t到如图 – 这里一般就选第一给(意思是为当前用户安装还是为所有用户安装,一般人都只有一个user,所以选第一个就可以了)
在这里插入图片描述
2、安装位置 – 建议安装在其他盘
在这里插入图片描述

3、选择配置 – 第一个一定要选上,默认不选的,它的作用是自动配置环境变量等,第二个可以选可以不选,如果让你选择就选。
在这里插入图片描述
4、安装好后,会在开始中多出Anaconda3文件夹;

在这里插入图片描述
点击Anaconda Prompt就可以打开类似cmd打开的命令行一样的窗口,进行相应
在这里插入图片描述
5、安装tensoflow(2020.8.27更新)
CPU版:
①直接联网安装,使用pip --default-timeout=100 install tensorflow -i https://pypi.douban.com/simple
②下载whl文件后安装,使用
pip --default-timeout=100 install tensorflow-2.3.0rc2-cp38-cp38-win32.whl -i https://pypi.douban.com/simple
GPU版:
①直接联网安装,使用pip --default-timeout=100 install tensorflow-gpu -i https://pypi.douban.com/simple
在这里插入图片描述

6、测试能否使用tensorflow(尝试导入import tensorflow可行不行)
居然还有提示失败:Could not load dynamic library ‘cudart64_101.dll’; dlerror: cudart64_101.dll not found;从字面意思可以看到是缺少了cudart64_101.dll文件(这个是安装cuda10.1才会有的)。

在这里插入图片描述
不慌,下载cudart64_101.dll文件,并放到D:\CUDA\NVIDIA GPU Computing Toolkit\bin(具体是你的cuda安装的文件夹下找,大概是安装时的development放的那个文件夹,找到bin)即可
直接可以去http://www.ijinshan.com/filerepair/cudart64_101.dll.shtml这里下载,选择手动下载文件修复
在这里插入图片描述
然后放进来
在这里插入图片描述
再测试,终于成功了
在这里插入图片描述

六、Anaconda与Pychram相关联
1、新建项目关联
(1)在这里插入图片描述
(2)
第一:创建新项目的同时创建新环境
在这里插入图片描述
第二:使用已有的环境
在这里插入图片描述
如果已经创建了项目,可以File -> settings -> Project:XXX(项目名称) -> Project Interpreter来设置,这里可以添加或者选择已有的来改,如果没有anaconda对应的python.exe,就选择Add,如第二张图片
在这里插入图片描述
在这里插入图片描述

关于环境的内容终于安装好了

  • 11
    点赞
  • 63
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
自编译tensorflow: 1.python3.5,tensorflow1.12; 2.支持cuda10.0,cudnn7.3.1,TensorRT-5.0.2.6-cuda10.0-cudnn7.3; 3.无mkl支持; 软硬件硬件环境:Ubuntu16.04,GeForce GTX 1080 TI 配置信息: hp@dla:~/work/ts_compile/tensorflow$ ./configure WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown". You have bazel 0.19.1 installed. Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3 Found possible Python library paths: /usr/local/lib/python3.5/dist-packages /usr/lib/python3/dist-packages Please input the desired Python library path to use. Default is [/usr/local/lib/python3.5/dist-packages] Do you wish to build TensorFlow with XLA JIT support? [Y/n]: XLA JIT support will be enabled for TensorFlow. Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: No OpenCL SYCL support will be enabled for TensorFlow. Do you wish to build TensorFlow with ROCm support? [y/N]: No ROCm support will be enabled for TensorFlow. Do you wish to build TensorFlow with CUDA support? [y/N]: y CUDA support will be enabled for TensorFlow. Please specify the CUDA SDK version you want to use. [Leave empty to default to CUDA 10.0]: Please specify the location where CUDA 10.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda-10.0 Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7]: 7.3.1 Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-10.0]: Do you wish to build TensorFlow with TensorRT support? [y/N]: y TensorRT support will be enabled for TensorFlow. Please specify the location where TensorRT is installed. [Default is /usr/lib/x86_64-linux-gnu]://home/hp/bin/TensorRT-5.0.2.6-cuda10.0-cudnn7.3/targets/x86_64-linux-gnu Please specify the locally installed NCCL version you want to use. [Default is to use https://github.com/nvidia/nccl]: Please specify a list of comma-separated Cuda compute capabilities you want to build with. You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 6.1,6.1,6.1]: Do you want to use clang as CUDA compiler? [y/N]: nvcc will be used as CUDA compiler. Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: Do you wish to build TensorFlow with MPI support? [y/N]: No MPI support will be enabled for TensorFlow. Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]: Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: Not configuring the WORKSPACE for Android builds. Preconfigured Bazel build configs. You can use any of the below by adding "--config=" to your build command. See .bazelrc for more details. --config=mkl # Build with MKL support. --config=monolithic # Config for mostly static monolithic build. --config=gdr # Build with GDR support. --config=verbs # Build with libverbs support. --config=ngraph # Build with Intel nGraph support. --config=dynamic_kernels # (Experimental) Build kernels into separate shared objects. Preconfigured Bazel build configs to DISABLE default on features: --config=noaws # Disable AWS S3 filesystem support. --config=nogcp # Disable GCP support. --config=nohdfs # Disable HDFS support. --config=noignite # Disable Apacha Ignite support. --config=nokafka # Disable Apache Kafka support. --config=nonccl # Disable NVIDIA NCCL support. Configuration finished 编译: bazel build --config=opt --verbose_failures //tensorflow/tools/pip_package:build_pip_package 卸载已有tensorflow: hp@dla:~/temp$ sudo pip3 uninstall tensorflow 安装自己编译的成果: hp@dla:~/temp$ sudo pip3 install tensorflow-1.12.0-cp35-cp35m-linux_x86_64.whl
自编译tensorflow: 1.python3.5,tensorflow1.12; 2.支持cuda10.0,cudnn7.3.1,TensorRT-5.0.2.6-cuda10.0-cudnn7.3; 3.支持mkl,无MPI; 软硬件硬件环境:Ubuntu16.04,GeForce GTX 1080 配置信息: hp@dla:~/work/ts_compile/tensorflow$ ./configure WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown". You have bazel 0.19.1 installed. Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3 Found possible Python library paths: /usr/local/lib/python3.5/dist-packages /usr/lib/python3/dist-packages Please input the desired Python library path to use. Default is [/usr/local/lib/python3.5/dist-packages] Do you wish to build TensorFlow with XLA JIT support? [Y/n]: XLA JIT support will be enabled for TensorFlow. Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: No OpenCL SYCL support will be enabled for TensorFlow. Do you wish to build TensorFlow with ROCm support? [y/N]: No ROCm support will be enabled for TensorFlow. Do you wish to build TensorFlow with CUDA support? [y/N]: y CUDA support will be enabled for TensorFlow. Please specify the CUDA SDK version you want to use. [Leave empty to default to CUDA 10.0]: Please specify the location where CUDA 10.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda-10.0 Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7]: 7.3.1 Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-10.0]: Do you wish to build TensorFlow with TensorRT support? [y/N]: y TensorRT support will be enabled for TensorFlow. Please specify the location where TensorRT is installed. [Default is /usr/lib/x86_64-linux-gnu]:/home/hp/bin/TensorRT-5.0.2.6-cuda10.0-cudnn7.3/targets/x86_64-linux-gnu Please specify the locally installed NCCL version you want to use. [Default is to use https://github.com/nvidia/nccl]: Please specify a list of comma-separated Cuda compute capabilities you want to build with. You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 6.1,6.1,6.1]: Do you want to use clang as CUDA compiler? [y/N]: nvcc will be used as CUDA compiler. Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: Do you wish to build TensorFlow with MPI support? [y/N]: No MPI support will be enabled for TensorFlow. Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]: Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: Not configuring the WORKSPACE for Android builds. Preconfigured Bazel build configs. You can use any of the below by adding "--config=" to your build command. See .bazelrc for more details. --config=mkl # Build with MKL support. --config=monolithic # Config for mostly static monolithic build. --config=gdr # Build with GDR support. --config=verbs # Build with libverbs support. --config=ngraph # Build with Intel nGraph support. --config=dynamic_kernels # (Experimental) Build kernels into separate shared objects. Preconfigured Bazel build configs to DISABLE default on features: --config=noaws # Disable AWS S3 filesystem support. --config=nogcp # Disable GCP support. --config=nohdfs # Disable HDFS support. --config=noignite # Disable Apacha Ignite support. --config=nokafka # Disable Apache Kafka support. --config=nonccl # Disable NVIDIA NCCL support. Configuration finished 编译: hp@dla:~/work/ts_compile/tensorflow$ bazel build --config=opt --config=mkl --verbose_failures //tensorflow/tools/pip_package:build_pip_package 卸载已有tensorflow: hp@dla:~/temp$ sudo pip3 uninstall tensorflow 安装自己编译的成果: hp@dla:~/temp$ sudo pip3 install tensorflow-1.12.0-cp35-cp35m-linux_x86_64.whl
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值