TensorFlow 最初由Google大腦小組(隸屬於Google機器智能研究機構)的研究員和工程師們開發出來,用於機器學習和深度神經網絡方面的研究,但這個系統的通用性使其也可普遍用於其餘計算領域。目前來講,Github上star最多的項目就是它了。python
在這以前,筆者寫過一篇簡單的入門文章《初探 TensorFlow》。當時沒能成功搭建環境,加上後期的工做緣由,至此擱置了一段時間。今天,終於各類折騰,在本身的Mac上通過多種嘗試以後,完美搭建成功。這裏就把它分享出來,但願對你們有所幫助。linux
Anaconda 是一個集成許多第三方科學計算庫的 Python
科學計算環境,Anaconda
使用 conda
做爲本身的包管理工具,同時具備本身的計算環境,相似 Virtualenv
.git
和 Virtualenv
同樣,不一樣 Python
工程須要的依賴包,conda
將他們存儲在不一樣的地方。 TensorFlow
上安裝的 Anaconda
不會對以前安裝的 Python
包進行覆蓋.github
conda
計算環境conda
安裝 TensorFlow
TensorFlow
的時候須要激活 conda
環境參考 Anaconda 的下載頁面的指導c#
創建一個 conda 計算環境名字叫tensorflow
:api
# Python 2.7
$ conda create -n tensorflow python=2.7
# Python 3.4
$ conda create -n tensorflow python=3.4
複製代碼
激活tensorflow
環境,而後使用其中的 pip
安裝 TensorFlow
. 當使用easy_install
使用--ignore-installed
標記防止錯誤的產生。bash
URL of the TensorFlow Python package網絡
$ source activate tensorflow
(tensorflow)$ # Your prompt should change
# Ubuntu/Linux 64-bit, CPU only, Python 2.7:
(tensorflow)$ pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0rc0-cp27-none-linux_x86_64.whl
# Ubuntu/Linux 64-bit, GPU enabled, Python 2.7. Requires CUDA toolkit 7.5 and CuDNN v4.
# For other versions, see "Install from sources" below.
(tensorflow)$ pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0rc0-cp27-none-linux_x86_64.whl
# Mac OS X, CPU only:
(tensorflow)$ pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0rc0-py2-none-any.whl
複製代碼
對於 Python 3.x :機器學習
$ source activate tensorflow
(tensorflow)$ # Your prompt should change
# Ubuntu/Linux 64-bit, CPU only, Python 3.4:
(tensorflow)$ pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0rc0-cp34-cp34m-linux_x86_64.whl
# Ubuntu/Linux 64-bit, GPU enabled, Python 3.4. Requires CUDA toolkit 7.5 and CuDNN v4.
# For other versions, see "Install from sources" below.
(tensorflow)$ pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0rc0-cp34-cp34m-linux_x86_64.whl
# Mac OS X, CPU only:
(tensorflow)$ pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0rc0-py3-none-any.whl
複製代碼
conda 環境激活後,你能夠測試:ide
$ python
>>> import tensorflow as tf
>>> print(tf.__version__)
# 0.11.0rc0
複製代碼
當你不用 TensorFlow 的時候,關閉環境:
(tensorflow)$ source deactivate
$ # Your prompt should change back
複製代碼
再次使用的時候再激活 :
$ source activate tensorflow
(tensorflow)$ # Your prompt should change.
# Run Python programs that use TensorFlow.
...
# When you are done using TensorFlow, deactivate the environment.
(tensorflow)$ source deactivate
複製代碼
**重點:**正確配置Project
的Interpreter
便可