Anaconda安装
在清华大学 TUNA 镜像源选择对应的操作系统与所需的Python版本下载Anaconda安装包。Windows环境下的安装包直接执行.exe文件进行安装即可,Ubuntu环境下在终端执行
$ bash Anaconda2-4.3.1-Linux-x86_64.sh#Python2.7版本
或者
$ bash Anaconda3-4.3.1-Linux-x86_64.sh#Python3.5版本
在安装的过程中,会询问安装路径,按回车即可。之后会询问是否将Anaconda安装路径加入到环境变量(.bashrc)中,输入yes,这样以后在终端中输入python即可直接进入Anaconda的Python版本(如果你的系统中之前安装过Python,自行选择yes or no)。安装成功后,会有当前用户根目录下生成一个anaconda2的文件夹,里面就是安装好的内容
查询安装信息
$ conda info
查询当前已经安装的库
$ condalist
安装库(***代表库名称)
$ conda install ***
更新库
$ conda update ***
Anaconda仓库镜像
官方下载更新工具包的速度很慢,所以继续添加清华大学 TUNA提供的Anaconda仓库镜像,在终端或cmd中输入如下命令进行添加
$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/$ conda config --setshow_channel_urls yes$ conda install numpy#测试是否添加成功
之后会自动在用户根目录生成“.condarc”文件,Ubuntu环境下路径为~/.condarc,Windows环境下路径为C:\用户\your_user_name\.condarc
channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
-defaults
show_channel_urls:yes
如果要删除镜像,直接删除“.condarc”文件即可
Tensorflow安装
在终端或cmd中输入以下命令搜索当前可用的tensorflow版本
$ anaconda search -t conda tensorflowUsing AnacondaAPI:https://api.anaconda.orgRun'anaconda show 'to get moredetails:Packages:Name | Version | Package Types | Platforms ------------------------- | ------ | --------------- | --------------- HCC/tensorflow |1.0.0| conda | linux-64HCC/tensorflow-cpucompat |1.0.0| conda | linux-64HCC/tensorflow-fma |1.0.0| conda | linux-64SentientPrime/tensorflow |0.6.0| conda | osx-64: TensorFlow helps the tensors flow acellera/tensorflow-cuda |0.12.1| conda | linux-64anaconda/tensorflow |1.0.1| conda | linux-64anaconda/tensorflow-gpu |1.0.1| conda | linux-64conda-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-64dhirschfeld/tensorflow |0.12.0rc0 | conda | win-64dseuss/tensorflow | | conda | osx-64guyanhua/tensorflow |1.0.0| conda | linux-64ijstokes/tensorflow |2017.03.03.1349| conda, ipynb | linux-64jjh_cio_testing/tensorflow |1.0.1| conda | linux-64jjh_cio_testing/tensorflow-gpu |1.0.1| conda | linux-64jjh_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-64kevin-keraudren/tensorflow |0.9.0| conda | linux-64lcls-rhel7/tensorflow |0.12.1| conda | linux-64marta-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-64msarahan/tensorflow |1.0.0rc2 | conda | linux-64mutirri/tensorflow |0.10.0rc0 | conda | linux-64mwojcikowski/tensorflow |1.0.1| conda | linux-64rdonnelly/tensorflow |0.9.0| conda | linux-64rdonnellyr/r-tensorflow |0.4.0| conda | osx-64test_org_002/tensorflow |0.10.0rc0 | conda | Found32packages
选择一个较新的CPU或GPU版本,如jjh_cio_testing/tensorflow-gpu的1.0.1版本,输入如下命令查询安装命令
$ anaconda show jjh_cio_testing/tensorflow-gpuUsing AnacondaAPI:https://api.anaconda.orgName:tensorflow-gpuSummary:Access:publicPackageTypes:condaVersions:+1.0.1To installthispackagewith condarun:conda install --channelhttps://conda.anaconda.org/jjh_cio_testing tensorflow-gpu
使用最后一行的提示命令进行安装
$ conda install --channelhttps://conda.anaconda.org/jjh_cio_testing tensorflow-gpuFetchingpackagemetadata .............Solvingpackagespecifications:.Package planforinstallationinenvironment/home/will/anaconda2:The following packages will be SUPERSEDED by a higher-prioritychannel:tensorflow-gpu:1.0.1-py27_4https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free --> 1.0.1-py27_4 jjh_cio_testingProceed ([y]/n)?
conda会自动检测安装此版本的Tensorflow所依赖的库,如果你的Anaconda缺少这些依赖库,会提示你安装。因为我之前已经安装过了,所以这里只提示我安装Tensorflow。输入y并回车之后等待安装结束即可
可以选择次高版本的Tensorflow安装,因为最新版本可能清华 TUNA的仓库镜像库没有及时更新,而官方更新连接总是失败,我最开始选择了jjhelmus/tensorflow-gpu的1.0.1版本,其他依赖库清华 TUNA的仓库镜像有资源,而到最后jjhelmus/tensorflow-gpu版本的Tensorflow安装包总是下载不下来,尝试20多次之后换了一个1.0.0的版本,终于顺利安装成功
进入python,输入
import tensorflowas tf
如果没有报错说明安装成功。