win10 + tensorflow_gpu 1.12.0 + CUDA 10.0 + Anaconda + RTX 2080 +pyCharm 环境搭建过程

前言

配置环境花了一天,也踩了一些坑,有幸有很多前人资料以供参考,自己也写一篇安装过程以帮助后来者。在此之前,做些简要的说明:

  • 本文仅记录本人环境搭建过程,不保证具有可复制性
  • 由于环境更新换代比较快,网上很多旧的博客参考性不大,最好找官方教程或较新博客
  • 切勿轻信一家之言,综合多个信息源往往可以事半功倍

Anaconda安装

下载网址:https://www.anaconda.com/distribution/
安装过程中的 Advanced Options 两个我都没有勾选:第一个勾,环境变量我是在安装后手动配置的;第二个勾,tensorflow1.12不支持Python3.7,随后手动配置即可。
环境变量如下,自行修改:

  • C:\MyProgram\Anaconda
  • C:\MyProgram\Anaconda\Scripts
  • C:\MyProgram\Anaconda\Library\bin

在cmd中输入 conda -V 显示版本号说明配置成功。

安装CUDA和cuDNN

tensorflow官方gpu支持:https://tensorflow.google.cn/install/gpu
tensorflow与CUDA对应版本:https://tensorflow.google.cn/install/source_windows#gpu
CUDA下载地址:https://developer.nvidia.com/cuda-toolkit-archive
tensorflow1.12官方只支持到CUDA9,因此我第一次下载的是推荐比较多的9.0版本,提示驱动没有支持2080显卡;之后下载的9.2版本,全部安装完成后import tensorflow时出现 ImportError: DLL load failed: 找不到指定的模块。错误,应该是版本问题,未解决;最后看到网上有人使用github上的大牛build的支持CUDA10.0 的tensorflow-gpu-1.12.0 wheel成功了,我便下载了CUDA10.0。

进入上述CUDA下载地址选择对应版本,Installer Type我选择的local,然后下载base installer,如果有patches的话也可都下载下来。
安装选项选择自定义,我不用vs所以没有勾选vs组件,特别注意显卡驱动中的版本,如果当前版本较低会自动升级到新版本,如果当前版本较高需要你先卸载当前驱动,再安装CUDA时会自动安装新版本,其他选项我全部勾选了。

之后下载cuDNN:https://developer.nvidia.com/rdp/cudnn-download
需要先免费注册一个账号,然后下载对应版本就好。
下载完成后解压,然后把三个文件夹拷贝到CUDA安装的根目录,即把cuDNN下bin中的dll文件拷贝到CUDA根目录的bin文件夹中,依次拷贝其他文件。

最后配置环境变量如下,自行修改:

  • C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0;
  • C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin;
  • C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64;
  • C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\libnvvp;

安装tensorflow-gpu

由于官方没有支持CUDA10.0,故从github上下载大牛build的wheel:https://github.com/fo40225/tensorflow-windows-wheel ,我使用的是
1.12.0\py36\GPU\cuda100cudnn73sse2。

首先创建conda环境(建议先设置清华源和科大源:https://blog.csdn.net/dream_allday/article/details/80344511)

conda create -n tensorflow python=3.6

然后激活conda环境

activate tensorflow

最后安装tensorflow

pip install  路径\tensorflow_gpu-1.12.0-cp36-cp36m-win_amd64.whl

至此,安装步骤全部完成。

测试

查看gpu使用情况

from tensorflow.python.client import device_lib 
device_lib.list_local_devices()

其他配置

  • 如果在cmd中可以import tensorflow,在pycharm中不可以,有两点要注意:
    • 设置python解释器到anaconda/envs/tensorflow目录下python.exe
    • 在pycharm中添加CUDA环境变量 ,详见https://github.com/tensorflow/tensorflow/issues/9530
  • 在sublime中需要安装conda包才可以使用创建的conda环境

祝各位学习顺利!

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
自编译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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值