ubantu18.04 RTX2070使用anaconda3安装tensorflow-gpu

版本问题:

RTX2070是nvidia出的新一代20系列显卡,都是图灵架构。要配合cuda10的版本,而且tensorflow 也要选择1.13版本。于是装了cuda最新的10.1,安装完毕,在import tensorflow时,报importError:DLL load failed:找不到指定的模块“这个错误,在另一篇文章中我已经说过,这个错误基本都是版本不对应的问题。于是想着是不是cuda版本太高了,卸载cuda10.1,重新安装cuda10.0,问题解决。
原文:https://blog.csdn.net/zhengxinjie2/article/details/89289544

 

本文使用anaconda安装tensorflw-gpu,会自动匹配安装cuda和cudnn,已安装conda请直接跳到4安装tensorflow

也可以手动用conda安装:

安装cuda:

    conda install cudatoolkit=8.0 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64/

安装cudnn:

    conda install cudnn=7.0.5 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/

下图展示的是安装CUDA和CUDNN以后的路径。
这里的安装路径没有单独形成cuda文件夹,都是统一存放在envs下的虚拟环境lib、include文件夹下

ubantu18.04 RTX2070使用anaconda3安装tensorflow-gpu_第1张图片

 

不使用conda时cuda和cudnn的安装过程见https://blog.csdn.net/qq_42412214/article/details/90142731

附:anaconda对应的python版本

ubantu18.04 RTX2070使用anaconda3安装tensorflow-gpu_第2张图片

首先解释一下上表。 anaconda在每次发布新版本的时候都会给python3和python2都发布一个包,版本号是一样的。

表格中,python版本号下方的离它最近的anaconda包就是包含它的版本。

举个例子,假设你想安装python2.7.14,在表格中找到它,它下方的三个anaconda包(anaconda2-5.0.1、5.1.0、5.2.0)都包含python2.7.14;

假设你想安装python3.6.5,在表格中找到它,它下方的anaconda3-5.2.0就是你需要下载的包;

假设你想安装python3.7.0,在表格中找到它,它下方的anaconda3-5.3.0或5.3.1就是你需要下载的包;

原文:https://blog.csdn.net/yuejisuo1948/article/details/81043823

也就是说,anaconda3-5.2.0只能安装3.6.5以下的python
 

1、安装anaconda3参考:

https://blog.csdn.net/qq_15192373/article/details/81091098

安装完成后需重启终端,或者输入source ~/.bashrc

再输入python就会进入anaconda的python版本

 

2、安装显卡驱动nvidia-driver

第一:检查显卡和推荐驱动:

ubuntu-drivers devices

若无显示,则先添加NVIDIA的PPA:

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update

显示推荐的驱动:

jason@jason:~$ ubuntu-drivers devices
== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00001F07sv000010DEsd000012ADbc03sc00i00
vendor   : NVIDIA Corporation
driver   : nvidia-driver-415 - third-party free
driver   : nvidia-driver-410 - third-party free
driver   : nvidia-driver-430 - third-party free recommended
driver   : nvidia-driver-418 - third-party free
driver   : xserver-xorg-video-nouveau - distro free builtin

选择410版本

首先添加apt-get的清华源,使安装速度更快:https://blog.csdn.net/qq_42412214/article/details/89055720

然后使用如下命令安装,这一步时间较长

sudo apt-get install nvidia-driver-410

安装成功:

jason@jason:~$ nvidia-smi
Sun Jul  7 02:00:19 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 410.104      Driver Version: 410.104      CUDA Version: 10.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce RTX 2070    Off  | 00000000:01:00.0 Off |                  N/A |
| 41%   49C    P0    39W / 185W |    196MiB /  7952MiB |      1%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1054      G   /usr/lib/xorg/Xorg                           106MiB |
|    0      1285      G   /usr/bin/gnome-shell                          88MiB |
+-----------------------------------------------------------------------------+

 

3、使用conda建立名为my-py-env的python环境

1)添加anaconda国内源,使anaconda安装环境更快

将以下配置文件写在~/.condarc中(初始为空文件)
vim ~/.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

原文:https://blog.csdn.net/observador/article/details/83618540

此处感觉添加的源网址有些少,部分包还是从官网上下的

2)建立一个新的python环境,名为my-py-env,使用python3.6.5

参考:https://blog.csdn.net/qq_31456593/article/dpetails/89090156

conda create -n my-py-env python=3.6.5

安装完成:

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use:
# > source activate my-py-env
#
# To deactivate an active environment, use:
# > source deactivate

若删除该python环境:

conda remove -n my-py-env --all

 

4、安装tensorflow

查看可用tensorflow版本参考:https://blog.csdn.net/shiheyingzhe/article/details/80863422

在新建的python环境安装tensorflow命令参考:https://www.jianshu.com/p/e6a9aa0e671b

jason@jason:~$ conda install -n my-py-env tensorflow-gpu
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.5.4
  latest version: 4.7.5

Please update conda by running

    $ conda update -n base conda



## Package Plan ##

  environment location: /home/jason/anaconda3/envs/my-py-env

  added / updated specs: 
    - tensorflow-gpu


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    cudnn-7.6.0                |       cuda10.0_0       216.6 MB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    cupti-10.0.130             |                0         1.8 MB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    markdown-3.1.1             |           py36_0         113 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    hdf5-1.10.4                |       hb1b8bf9_0         5.3 MB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    scipy-1.2.1                |   py36h7c811a0_0        17.7 MB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    termcolor-1.1.0            |           py36_1           7 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    cudatoolkit-10.0.130       |                0       380.0 MB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    blas-1.0                   |              mkl           6 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    mock-3.0.5                 |           py36_0          47 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    mkl-2019.4                 |              243       204.1 MB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    numpy-base-1.16.4          |   py36hde5b4d6_0         4.4 MB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    libgfortran-ng-7.3.0       |       hdf63c60_0         1.3 MB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    grpcio-1.14.1              |   py36h9ba97e2_0         1.0 MB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    werkzeug-0.15.4            |             py_0         262 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    _tflow_select-2.1.0        |              gpu           2 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    protobuf-3.8.0             |   py36he6710b0_0         690 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    intel-openmp-2019.4        |              243         876 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    tensorflow-estimator-1.13.0|             py_0         205 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    numpy-1.16.4               |   py36h7e9f1db_0          49 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    mkl_random-1.0.2           |   py36hd81dba3_0         407 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    mkl_fft-1.0.12             |   py36ha843d7b_0         172 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    h5py-2.9.0                 |   py36h7918eee_0         1.2 MB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    six-1.12.0                 |           py36_0          22 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    tensorboard-1.13.1         |   py36hf484d3e_0         3.3 MB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    libprotobuf-3.8.0          |       hd408876_0         4.7 MB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    absl-py-0.7.1              |           py36_0         157 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    tensorflow-1.13.1          |gpu_py36h3991807_0           4 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    gast-0.2.2                 |           py36_0         138 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    tensorflow-gpu-1.13.1      |       h0d30ee6_0           2 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    c-ares-1.15.0              |       h7b6447c_1          98 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    keras-applications-1.0.8   |             py_0          33 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    astor-0.7.1                |           py36_0          43 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    tensorflow-base-1.13.1     |gpu_py36h8d69cac_0       293.8 MB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    keras-preprocessing-1.1.0  |             py_1          36 KB  https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    ------------------------------------------------------------
                                           Total:        1.11 GB

The following NEW packages will be INSTALLED:

    _tflow_select:        2.1.0-gpu                 https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    absl-py:              0.7.1-py36_0              https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    astor:                0.7.1-py36_0              https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    blas:                 1.0-mkl                   https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    c-ares:               1.15.0-h7b6447c_1         https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    cudatoolkit:          10.0.130-0                https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    cudnn:                7.6.0-cuda10.0_0          https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    cupti:                10.0.130-0                https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    gast:                 0.2.2-py36_0              https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    grpcio:               1.14.1-py36h9ba97e2_0     https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    h5py:                 2.9.0-py36h7918eee_0      https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    hdf5:                 1.10.4-hb1b8bf9_0         https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    intel-openmp:         2019.4-243                https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    keras-applications:   1.0.8-py_0                https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    keras-preprocessing:  1.1.0-py_1                https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    libgfortran-ng:       7.3.0-hdf63c60_0          https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    libprotobuf:          3.8.0-hd408876_0          https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    markdown:             3.1.1-py36_0              https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    mkl:                  2019.4-243                https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    mkl_fft:              1.0.12-py36ha843d7b_0     https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    mkl_random:           1.0.2-py36hd81dba3_0      https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    mock:                 3.0.5-py36_0              https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    numpy:                1.16.4-py36h7e9f1db_0     https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    numpy-base:           1.16.4-py36hde5b4d6_0     https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    protobuf:             3.8.0-py36he6710b0_0      https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    scipy:                1.2.1-py36h7c811a0_0      https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    six:                  1.12.0-py36_0             https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    tensorboard:          1.13.1-py36hf484d3e_0     https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    tensorflow:           1.13.1-gpu_py36h3991807_0 https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    tensorflow-base:      1.13.1-gpu_py36h8d69cac_0 https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    tensorflow-estimator: 1.13.0-py_0               https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    tensorflow-gpu:       1.13.1-h0d30ee6_0         https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    termcolor:            1.1.0-py36_1              https://mirrors.ustc.edu.cn/anaconda/pkgs/main
    werkzeug:             0.15.4-py_0               https://mirrors.ustc.edu.cn/anaconda/pkgs/main

Proceed ([y]/n)? 

输入yes进行安装

conda install -n my-py-env tensorflow-gpu==XXX可以选择版本

安装成功

jason@jason:~$ source activate my-py-env
(my-py-env) jason@jason:~$ python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
'1.13.1'

 

你可能感兴趣的:(环境安装,tensorflow)