맥에 Tensorflow를 설치하는 과정은 아래 홈페이지에 자세히 나와있다.

https://www.tensorflow.org/install/install_mac 


하지만 중간에 안되는 경우도 있고 어떤걸 선택해야 할지 망설여지는 부분이 있어서 여기에 별도로 정리해둔다.

pip 설치방법을 따른다.


먼저 설치하는 시스템은 다음과 같다.

OSX Yosemite 10.10.5 가 설치된 mac mini(late 2014)

Intel i5 2.6 GHz, 8Gb 1600 MHz DDR3 가 탑재됨


먼저 Python 2.7.12 이 설치되었는지 확인한다.
만약 설치되어 있다면 터미널에 python을 입력하면 된다.

안되어 있다면 brew 를 사용하여 설치한다. 


자세한 설치 방법은 아래 링크 참조.

https://brew.sh/index_ko.html


$ sudo easy_install pip


Searching for pip

Best match: pip 8.1.2

Processing pip-8.1.2-py2.7.egg

Adding pip 8.1.2 to easy-install.pth file

Installing pip script to /usr/local/bin

Installing pip2.7 script to /usr/local/bin

Installing pip2 script to /usr/local/bin


Using /Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg

Processing dependencies for pip

Finished processing dependencies for pip


$ sudo easy_install --upgrade six


Searching for six

Reading https://pypi.python.org/simple/six/

Best match: six 1.10.0

Downloading https://pypi.python.org/packages/b3/b2/238e2590826bfdd113244a40d9d3eb26918bd798fc187e2360a8367068db/six-1.10.0.tar.gz#md5=34eed507548117b2ab523ab14b2f8b55

Processing six-1.10.0.tar.gz

Writing /tmp/easy_install-RkxZZ9/six-1.10.0/setup.cfg

Running six-1.10.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-RkxZZ9/six-1.10.0/egg-dist-tmp-Ddajal

no previously-included directories found matching 'documentation/_build'

zip_safe flag not set; analyzing archive contents...

six: module references __path__

creating /usr/local/lib/python2.7/site-packages/six-1.10.0-py2.7.egg

Extracting six-1.10.0-py2.7.egg to /usr/local/lib/python2.7/site-packages

Adding six 1.10.0 to easy-install.pth file


Installed /usr/local/lib/python2.7/site-packages/six-1.10.0-py2.7.egg

Processing dependencies for six

Finished processing dependencies for six


pip를 업데이트한다.

$ sudo easy_install --upgrade pip


Searching for pip

Reading https://pypi.python.org/simple/pip/

Best match: pip 9.0.1

Downloading https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9

Processing pip-9.0.1.tar.gz

Writing /tmp/easy_install-x3qv93/pip-9.0.1/setup.cfg

Running pip-9.0.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-x3qv93/pip-9.0.1/egg-dist-tmp-XABGSr

/usr/local/Cellar/python/2.7.12_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'

  warnings.warn(msg)

warning: no previously-included files found matching '.coveragerc'

warning: no previously-included files found matching '.mailmap'

warning: no previously-included files found matching '.travis.yml'

warning: no previously-included files found matching '.landscape.yml'

warning: no previously-included files found matching 'pip/_vendor/Makefile'

warning: no previously-included files found matching 'tox.ini'

warning: no previously-included files found matching 'dev-requirements.txt'

warning: no previously-included files found matching 'appveyor.yml'

no previously-included directories found matching '.github'

no previously-included directories found matching '.travis'

no previously-included directories found matching 'docs/_build'

no previously-included directories found matching 'contrib'

no previously-included directories found matching 'tasks'

no previously-included directories found matching 'tests'

creating /usr/local/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg

Extracting pip-9.0.1-py2.7.egg to /usr/local/lib/python2.7/site-packages

Removing pip 8.1.2 from easy-install.pth file

Adding pip 9.0.1 to easy-install.pth file

Installing pip script to /usr/local/bin

Installing pip2.7 script to /usr/local/bin

Installing pip2 script to /usr/local/bin


Installed /usr/local/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg

Processing dependencies for pip

Finished processing dependencies for pip



Tensor flow 설치하기

$ pip install --upgrade TF_BINARY_URL # Python 2.7

여기서 TF_BINARY_URL은 텐서플로우의 바이너리가 있는 링크이다.

https://www.tensorflow.org/install/install_mac#the_url_of_the_tensorflow_python_package 에서 찾을 수 있다.


Python 2.7 에 GPU가 없는 버전은 다음 위치에 있다.

https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.1.0-py2-none-any.whl

이제 터미널에 다음을 입력한다.

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


그럼 다음과 같이 설치를 진행할 것이다.


The directory '/Users/macmini2/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

The directory '/Users/macmini2/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

Collecting tensorflow==1.1.0 from https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.1.0-py2-none-any.whl

  Downloading https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.1.0-py2-none-any.whl (30.9MB)

    100% |████████████████████████████████| 30.9MB 39kB/s 

Requirement already up-to-date: six>=1.10.0 in /usr/local/lib/python2.7/site-packages/six-1.10.0-py2.7.egg (from tensorflow==1.1.0)

Collecting werkzeug>=0.11.10 (from tensorflow==1.1.0)

  Downloading Werkzeug-0.12.2-py2.py3-none-any.whl (312kB)

    100% |████████████████████████████████| 317kB 2.4MB/s 

Collecting numpy>=1.11.0 (from tensorflow==1.1.0)

  Downloading numpy-1.12.1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (4.4MB)

    100% |████████████████████████████████| 4.4MB 246kB/s 

Collecting mock>=2.0.0 (from tensorflow==1.1.0)

  Downloading mock-2.0.0-py2.py3-none-any.whl (56kB)

    100% |████████████████████████████████| 61kB 7.1MB/s 

Collecting protobuf>=3.2.0 (from tensorflow==1.1.0)

  Downloading protobuf-3.3.0.tar.gz (271kB)

    100% |████████████████████████████████| 276kB 1.4MB/s 

Requirement already up-to-date: wheel in /usr/local/lib/python2.7/site-packages (from tensorflow==1.1.0)

Collecting funcsigs>=1; python_version < "3.3" (from mock>=2.0.0->tensorflow==1.1.0)

  Downloading funcsigs-1.0.2-py2.py3-none-any.whl

Collecting pbr>=0.11 (from mock>=2.0.0->tensorflow==1.1.0)

  Downloading pbr-3.0.1-py2.py3-none-any.whl (99kB)

    100% |████████████████████████████████| 102kB 9.7MB/s 

Collecting setuptools (from protobuf>=3.2.0->tensorflow==1.1.0)

  Downloading setuptools-35.0.2-py2.py3-none-any.whl (390kB)

    100% |████████████████████████████████| 399kB 1.4MB/s 

Collecting packaging>=16.8 (from setuptools->protobuf>=3.2.0->tensorflow==1.1.0)

  Downloading packaging-16.8-py2.py3-none-any.whl

Collecting appdirs>=1.4.0 (from setuptools->protobuf>=3.2.0->tensorflow==1.1.0)

  Downloading appdirs-1.4.3-py2.py3-none-any.whl

Collecting pyparsing (from packaging>=16.8->setuptools->protobuf>=3.2.0->tensorflow==1.1.0)

  Downloading pyparsing-2.2.0-py2.py3-none-any.whl (56kB)

    100% |████████████████████████████████| 61kB 10.2MB/s 

Installing collected packages: werkzeug, numpy, funcsigs, pbr, mock, pyparsing, packaging, appdirs, setuptools, protobuf, tensorflow

  Found existing installation: setuptools 23.1.0

    Uninstalling setuptools-23.1.0:

      Successfully uninstalled setuptools-23.1.0

  Running setup.py install for protobuf ... done

Successfully installed appdirs-1.4.3 funcsigs-1.0.2 mock-2.0.0 numpy-1.12.1 packaging-16.8 pbr-3.0.1 protobuf-3.3.0 pyparsing-2.2.0 setuptools-35.0.2 tensorflow-1.1.0 werkzeug-0.12.2


이제 Python 을 실행하고 간단히 텐서플로우를 실행해보자.


>>> import tensorflow as tf

>>> hello = tf.constant('Hello, TensorFlow!!')

>>> sess = tf.Session()

2017-05-19 18:44:21.889118: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.

2017-05-19 18:44:21.889137: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.

2017-05-19 18:44:21.889147: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.

2017-05-19 18:44:21.889156: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.

2017-05-19 18:44:21.889165: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.

>>> print(sess.run(hello))

Hello, TensorFlow!!


위와 같이 정상적으로 출력됨을 확인할 수 있다.


+ Recent posts