MAC上安裝TensorFlow
Jan 21, 2017
1 minute read

安迪兒之前是在nas上試玩docker的TensorFlow
最近剛好做個小東西,趁機會記錄一下安裝TensorFlow在mac筆電的步驟

[相關文章]

為何Google要推開源機器學習系統TensorFlow?
原文網址:https://www.bnext.com.tw/article/37925/BN-2015-11-10-184646-40

TensorFlow官方安裝文件
原文網址:https://www.tensorflow.org/get_started/os_setup

安裝方式

  • Pip install:

Install TensorFlow on your machine, possibly upgrading previously installed Python packages. May impact existing Python programs on your machine.

  • Virtualenv install:

Install TensorFlow in its own directory, not impacting any existing Python programs on your machine.

  • Anaconda install:

Install TensorFlow in its own environment for those running the Anaconda Python distribution. Does not impact existing Python programs on your machine.

  • Docker install:

Run TensorFlow in a Docker container isolated from all other programs on your machine.

  • Installing from sources:

Install TensorFlow by building a pip wheel that you then install using pip.

安裝pip

如果沒pip的話可以先安裝一下

#Mac OS X  
$ sudo easy_install pip  
$ sudo easy_install --upgrade six  

安裝TensorFlow

安迪兒的Mac筆電沒有顯卡,只能裝CPU版的

CPU版:
 pip install tensorflow  

GPU版:
pip install tensorflow-gpu

然後踩了一下雷


查了一下發現mac好像都會有這問題
(其實官方文件下面一些有提到不能安裝時的方式)

安迪兒挑了mac內建的python2.7來用

Mac OS X, CPU only, Python 2.7:  
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py2-none-any.whl

更新一下tensorflow

# Python 2
$ sudo pip install --upgrade $TF_BINARY_URL

再次踩雷


還是error
安迪兒看了一下文件,覺的可能是和python的版本有關
就手動升了一下mac的python到2.7.13

brew install python  
brew info python  
brew linkapps python
source ~/.bash_profile
python -v



重來一次

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py2-none-any.whl  
sudo pip install --upgrade $TF_BINARY_URL  

安裝成功了

來測試一下tensorflow能不能用吧

$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a + b))
42
>>>

成功嘍

以上是安迪兒整個在mac安裝tensorflow的過程,收工嘍!


Back to posts


comments powered by Disqus