Anaconda+Tensorflow環境安裝與配置

轉載請註明出處:http://www.cnblogs.com/willnote/p/6746499.htmlhtml

Anaconda安裝

清華大學 TUNA 鏡像源選擇對應的操做系統與所需的Python版本下載Anaconda安裝包。Windows環境下的安裝包直接執行.exe文件進行安裝便可,Ubuntu環境下在終端執行python

$ bash Anaconda2-4.3.1-Linux-x86_64.sh   #Python 2.7版本

或者linux

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

在安裝的過程當中,會詢問安裝路徑,按回車便可。以後會詢問是否將Anaconda安裝路徑加入到環境變量(.bashrc)中,輸入yes,這樣之後在終端中輸入python便可直接進入Anaconda的Python版本(若是你的系統中以前安裝過Python,自行選擇yes or no)。安裝成功後,會有當前用戶根目錄下生成一個anaconda2的文件夾,裏面就是安裝好的內容shell

查詢安裝信息vim

$ conda info

查詢當前已經安裝的庫api

$ conda list

安裝庫(***表明庫名稱)bash

$ conda install ***

更新庫工具

$ conda update ***

Anaconda倉庫鏡像

官方下載更新工具包的速度很慢,因此繼續添加清華大學 TUNA提供的Anaconda倉庫鏡像,在終端或cmd中輸入以下命令進行添加學習

$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
$ conda config --set show_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 tensorflow

Using Anaconda API: https://api.anaconda.org
Run 'anaconda show <USER/PACKAGE>' 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並回車以後等待安裝結束便可

  • 能夠選擇次高版本的Tensorflow安裝,由於最新版本可能清華 TUNA的倉庫鏡像庫沒有及時更新,而官方更新鏈接老是失敗,我最開始選擇了jjhelmus/tensorflow-gpu的1.0.1版本,其餘依賴庫清華 TUNA的倉庫鏡像有資源,而到最後jjhelmus/tensorflow-gpu版本的Tensorflow安裝包老是下載不下來,嘗試20屢次以後換了一個1.0.0的版本,終於順利安裝成功

進入python,輸入

import tensorflow as tf

若是沒有報錯說明安裝成功。

參考

  1. Anaconda 鏡像使用幫助
  2. tensorflow學習筆記一:安裝調試
相關文章
相關標籤/搜索