使用Anaconda镜像安装tensorflow

可能自己比较笨,每次都用tensorflow源码下载再安装,而且超级慢。现在介绍用清华的镜像安装,超级方便。方便自己以后查用。

首先安装Anaconda

在清华镜像(点击阅读原文)上选择你需要的版本。window双击exe文件即可。ubuntu如下:

$ bash Anaconda3-4.3.1-Linux-x86_64.sh  #Python 3.5 版

Anaconda仓库镜像

添加仓库镜像到用户根目录“.condarc”文件。

1$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
2$ conda config --set show_channel_urls yes
3$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
4$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
5$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
6$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
7$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
8$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
9$ conda install numpy   #测试是否添加成功

查看此文件内容,如下:

channels:
 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
 - defaults
show_channel_urls: yes

安装tensorflow

我习惯在conda下建立不同项目所需要的环境,独立开来。

$ conda create -n tensorflow python=3.5 

命令行下查看当前可用tensorflow版本。

alice@alice:~$ source activate tensorflow_1
(tensorflow_1) alice@alice:~$ anaconda search -t conda tensorflow
Using Anaconda API: https://api.anaconda.org
Packages:
     Name                      |  Version | Package Types   | Platforms       | Builds    
     ------------------------- |   ------ | --------------- | --------------- | ----------
     GlaxoSmithKline/tensorflow |   0.12.0 | conda           | linux-64        | py27hb0d0e74_0
                                          : TensorFlow is a machine learning library
     HCC/tensorflow            |    1.7.0 | conda           | linux-64        | py34_1, py27_1, py27_0, py36_0, np113py35_0, np113py27_0, np113py36_0, py35_0, py35_1
                                          : Computation using data flow graphs for scalable machine learning.
     HCC/tensorflow-cpucompat  |    1.5.0 | conda           | linux-64        | py27_0, py36_0, py34_0, np113py35_0, np113py27_0, np113py36_0, py35_0
                                          : Computation using data flow graphs for scalable machine learning.
     HCC/tensorflow-fma        |    1.5.0 | conda           | linux-64        | py27_1, py34_1, py27_0, py36_0, py34_0, np113py35_0, np113py27_0, np113py36_0, py35_0, py35_1
...
Found 82 packages
Run 'anaconda show <USER/PACKAGE>' to get installation details

自行选择你需要的版本,比如RMG/tensorflow,然后输入以下来查询安装命令。

$ anaconda show RMG/tensorflow
Using Anaconda API: https://api.anaconda.org
Name:    tensorflow
Summary: 
Access:  public
Package Types:  conda
Versions:
   + 1.0.0
To install this package with conda run:
     conda install --channel https://conda.anaconda.org/RMG tensorflow

使用最后一行命令进行安装。

$ conda install --channel https://conda.anaconda.org/RMG tensorflow
Solving environment: - 
Warning: >10 possible package resolutions (only showing differing packages):
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::funcsigs-1.0.2-py27_0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::mkl-2017.0.3-0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::mock-2.0.0-py27_0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::pbr-1.10.0-py27_0
  - http://mirrors.ustc.edu.cn/anaconda/pkgs/free::funcsigs-1.0.2-py27_0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::mkl-2017.0.3-0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::mock-2.0.0-py27_0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::pbr-1.10.0-py27_0
  - http://mirrors.ustc.edu.cn/anaconda/pkgs/free::pbr-1.10.0-py27_0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::funcsigs-1.0.2-py27_0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::mkl-2017.0.3-0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::mock-2.0.0-py27_0
  - http://mirrors.ustc.edu.cn/anaconda/pkgs/free::funcsigs-1.0.2-py27_0, http://mirrors.ustc.edu.cn/anaconda/pkgs/free::pbr-1.10.0-py27_0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::mkl-2017.0.3-0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::mock-2.0.0-py27_0
  - http://mirrors.ustc.edu.cn/anaconda/pkgs/free::mock-2.0.0-py27_0, http://mirrors.ustc.edu.cn/anaconda/pkgs/free::pbr-1.10.0-py27_0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::funcsigs-1.0.2-py27_0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::mkl-2017.0.3-0
  - http://mirrors.ustc.edu.cn/anaconda/pkgs/free::funcsigs-1.0.2-py27_0, http://mirrors.ustc.edu.cn/anaconda/pkgs/free::mock-2.0.0-py27_0, http://mirrors.ustc.edu.cn/anaconda/pkgs/free::pbr-1.10.0-py27_0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::mkl-2017.0.3-0
  - http://mirrors.ustc.edu.cn/anaconda/pkgs/free::mock-2.0.0-py27_0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::funcsigs-1.0.2-py27_0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::mkl-2017.0.3-0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::pbr-1.10.0-py27_0
  - http://mirrors.ustc.edu.cn/anaconda/pkgs/free::funcsigs-1.0.2-py27_0, http://mirrors.ustc.edu.cn/anaconda/pkgs/free::mock-2.0.0-py27_0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::mkl-2017.0.3-0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::pbr-1.10.0-py27_0
  - http://mirrors.ustc.edu.cn/anaconda/pkgs/free::mkl-2017.0.3-0, http://mirrors.ustc.edu.cn/anaconda/pkgs/free::mock-2.0.0-py27_0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::funcsigs-1.0.2-py27_0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::pbr-1.10.0-py27_0
  - http://mirrors.ustc.edu.cn/anaconda/pkgs/free::mkl-2017.0.3-0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::funcsigs-1.0.2-py27_0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::mock-2.0.0-py27_0, https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free::pbr-1.10.0-py27_0
  ... and othedone
==> WARNING: A newer version of conda exists. <==
  current version: 4.5.1
  latest version: 4.5.4
Please update conda by running
    $ conda update -n base conda
## Package Plan ##
  environment location: /home/alice/anaconda3/envs/tensorflow_1
  added / updated specs: 
    - tensorflow
The following packages will be downloaded:
    package                    |            build
    ---------------------------|-----------------
    pbr-1.10.0                 |           py27_0         100 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    numpy-1.13.1               |           py27_0         6.8 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    six-1.10.0                 |           py27_0          16 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    tensorflow-1.0.0           |           py27_0        34.9 MB  RMG
    mock-2.0.0                 |           py27_0          96 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    funcsigs-1.0.2             |           py27_0          18 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    protobuf-3.4.0             |           py27_0         469 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    ------------------------------------------------------------
                                           Total:        42.4 MB
The following NEW packages will be INSTALLED:
    funcsigs:    1.0.2-py27_0  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    libprotobuf: 3.4.0-0       https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    mkl:         2017.0.3-0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    mock:        2.0.0-py27_0  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    numpy:       1.13.1-py27_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    pbr:         1.10.0-py27_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    protobuf:    3.4.0-py27_0  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    six:         1.10.0-py27_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    tensorflow:  1.0.0-py27_0  RMG                                                    
Proceed ([y]/n)? y
Downloading and Extracting Packages
pbr 1.10.0############################################################## | 100% 
numpy 1.13.1############################################################ | 100% 
six 1.10.0############################################################## | 100% 
tensorflow 1.0.0######################################################## | 100% 
mock 2.0.0############################################################## | 100% 
funcsigs 1.0.2########################################################## | 100% 
protobuf 3.4.0########################################################## | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

测试是否安装成功。

>>> import tensorflow as tf

如果没有报错,则安装成功。

    原文作者:菜园子
    原文地址: https://zhuanlan.zhihu.com/p/50571063
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞