Ubuntu14.04下安装anaconda以及TensorFlow教程

本文中所有的操作基本基于命令行,ubuntu下,进入命令行的操作 ctrl+alt+T

一:准备工作

1.1 创建文件存放安装包

$ sudo mkdir anaconda_package

1.2 进入该目录

$ cd anaconda_package

二:Anaconda安装

在清华大学 TUNA 镜像源选择对应的操作系统与所需的Python版本下载Anaconda安装包。Windows环境下的安装包直接执行.exe文件进行安装即可,Ubuntu环境下在终端执行

2.1 下载

$ wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda-1.4.0-Linux-x86.sh

2.2 安装

$ bash Anaconda-1.4.0-Linux-x86.sh

这里给出清华源的所有anaconda包的链接
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

2.3 查询安装信息

$ conda info

2.4 查询当前已经安装的库

$ conda list

2.5 验证conda已被安装

conda --version

2.6 卸载conda

sudo rm -rf ~/anaconda3

三:Anaconda仓库镜像

官方下载更新工具包的速度很慢,所以继续添加清华大学 TUNA提供的Anaconda仓库镜像,在终端或cmd中输入如下命令进行添加

$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
$ conda config --set show_channel_urls yes

四:管理环境

4.1 创建新环境

$ conda create --name  
  1. 即创建的环境名。建议以英文命名,且不加空格,名称两边不加尖括号“<>”。
  1. 即安装在环境中的包名。名称两边不加尖括号“<>”。
  1. 如果要安装指定的版本号,则只需要在包名后面以 = 和版本号的形式执行。如: conda create --name python2 python=2.7 ,即创建一个名为“python2”的环境,环境中安装版本为2.7的python。
  1. 如果要在新创建的环境中创建多个包,则直接在 后以空格隔开,添加多个包名即可。如: conda create -n python3 python=3.5 numpy pandas ,即创建一个名为“python3”的环境,环境中安装版本为3.5的python,同时也安装了numpy和pandas。

4.2 切换环境

$ source activate 

4.3 退出环境

source deactivate

4.4. 显示已创建环境

conda info -e

4.5 复制环境

conda create --name  --clone 
  1. 即为被复制/克隆环境名。环境名两边不加尖括号“<>”。
  1. 即为复制之后新环境的名称。环境名两边不加尖括号“<>”。
  2. conda create --name py3 --clone python3 ,即为克隆名为“python3”的环境,克隆后的新环境名为“py3”。此时,环境中将同时存在“python3”和“py3”环境,且两个环境的配置相同。

4.6 删除环境

conda remove --name  --all

为被删除环境的名称。环境名两边不加尖括号“<>”。

五:管理包、

5.1. 查找可供安装的包版本

  1. 精确查找
conda search --full-name 
  1. --full-name 为精确查找的参数。
  1. 是被查找包的全名。包名两边不加尖括号“<>”。 例如: conda search --full-name python 即查找全名为“python”的包有哪些版本可供安装。
  1. 模糊查找
conda search 

是查找含有此字段的包名。此字段两边不加尖括号“<>”。
例如: conda search py 即查找含有“py”字段的包,有哪些版本可供安装。

5.2 获取当前环境中已安装的包信息

conda list

5.3 安装包

conda install 

即要安装的包名。包名两边不加尖括号“<>”

5.4 安装numpy,scipy, pandas

conda install numpy scipy pandas 

5.4 卸载包

conda remove 

即要卸载包的名称。包名两边不加尖括号“<>”

5.5 更新包

  1. 更新所有包
conda update --all
  1. 更新指定包
conda update 

六: 安装TensorFlow案例

$ anaconda search -t conda tensorflow

Using Anaconda API: https://api.anaconda.org
Run 'anaconda show ' to get more details:
Packages:
     Name                      |  Version | Package Types   | Platforms      
     ------------------------- |   ------ | --------------- | ---------------
     HCC/tensorflow            |    1.0.0 | conda           | linux-64       
     HCC/tensorflow-cpucompat  |    1.0.0 | conda           | linux-64       
     HCC/tensorflow-fma        |    1.0.0 | conda           | linux-64       
     SentientPrime/tensorflow  |    0.6.0 | conda           | osx-64         
                                          : TensorFlow helps the tensors flow
     acellera/tensorflow-cuda  |   0.12.1 | conda           | linux-64       
     anaconda/tensorflow       |    1.0.1 | conda           | linux-64       
     anaconda/tensorflow-gpu   |    1.0.1 | conda           | linux-64       
     conda-forge/tensorflow    |    1.0.0 | conda           | linux-64, win-64, osx-64
                                          : TensorFlow helps the tensors flow
     creditx/tensorflow        |    0.9.0 | conda           | linux-64       
                                          : TensorFlow helps the tensors flow
     derickl/tensorflow        |   0.12.1 | conda           | osx-64         
     dhirschfeld/tensorflow    | 0.12.0rc0 | conda           | win-64         
     dseuss/tensorflow         |          | conda           | osx-64         
     guyanhua/tensorflow       |    1.0.0 | conda           | linux-64       
     ijstokes/tensorflow       | 2017.03.03.1349 | conda, ipynb    | linux-64       
     jjh_cio_testing/tensorflow |    1.0.1 | conda           | linux-64       
     jjh_cio_testing/tensorflow-gpu |    1.0.1 | conda           | linux-64       
     jjh_ppc64le/tensorflow    |    1.0.1 | conda           | linux-ppc64le  
     jjh_ppc64le/tensorflow-gpu |    1.0.1 | conda           | linux-ppc64le  
     jjhelmus/tensorflow       | 0.12.0rc0 | conda, pypi     | linux-64, osx-64
                                          : TensorFlow helps the tensors flow
     jjhelmus/tensorflow-gpu   |    1.0.1 | conda           | linux-64       
     kevin-keraudren/tensorflow |    0.9.0 | conda           | linux-64       
     lcls-rhel7/tensorflow     |   0.12.1 | conda           | linux-64       
     marta-sd/tensorflow       |    1.0.1 | conda           | linux-64       
                                          : TensorFlow helps the tensors flow
     memex/tensorflow          |    0.5.0 | conda           | linux-64, osx-64
                                          : TensorFlow helps the tensors flow
     mhworth/tensorflow        |    0.7.1 | conda           | osx-64         
                                          : TensorFlow helps the tensors flow
     miovision/tensorflow      | 0.10.0.gpu | conda           | linux-64, osx-64
     msarahan/tensorflow       | 1.0.0rc2 | conda           | linux-64       
     mutirri/tensorflow        | 0.10.0rc0 | conda           | linux-64       
     mwojcikowski/tensorflow   |    1.0.1 | conda           | linux-64       
     rdonnelly/tensorflow      |    0.9.0 | conda           | linux-64       
     rdonnellyr/r-tensorflow   |    0.4.0 | conda           | osx-64         
     test_org_002/tensorflow   | 0.10.0rc0 | conda           |                
Found 32 packages

选择一个较新的CPU或GPU版本,如jjh_cio_testing/tensorflow-gpu的1.0.1版本,输入如下命令查询安装命令

$ anaconda show jjh_cio_testing/tensorflow-gpu

Using Anaconda API: https://api.anaconda.org
Name:    tensorflow-gpu
Summary: 
Access:  public
Package Types:  conda
Versions:
   + 1.0.1

To install this package with conda run:
     conda install --channel https://conda.anaconda.org/jjh_cio_testing tensorflow-gpu

使用最后一行的提示命令进行安装

$ conda install --channel https://conda.anaconda.org/jjh_cio_testing tensorflow-gpu

Fetching package metadata .............
Solving package specifications: .

Package plan for installation in environment /home/will/anaconda2:

The following packages will be SUPERSEDED by a higher-priority channel:

    tensorflow-gpu: 1.0.1-py27_4 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free --> 1.0.1-py27_4 jjh_cio_testing

Proceed ([y]/n)?

conda会自动检测安装此版本的Tensorflow所依赖的库,如果你的Anaconda缺少这些依赖库,会提示你安装。因为我之前已经安装过了,所以这里只提示我安装Tensorflow。输入y并回车之后等待安装结束即可
进入python,输入

>>> import tensorflow as tf
>>>

如果没有报错说明安装成功。

七:参考文档

  1. http://www.jianshu.com/p/7be2498785b1
  2. https://zhuanlan.zhihu.com/p/32925500

你可能感兴趣的:(Ubuntu14.04下安装anaconda以及TensorFlow教程)