LoginSignup
5
4

More than 5 years have passed since last update.

TensorFlow 0.11.0rc2のOS X El Capitan (10.11.6) へのインストール

Last updated at Posted at 2016-11-03

TensorFlow の勉強をはじめます。

まずは環境を準備します。
プラットフォームは OS X El Capitan (10.11.6) です。

公式ドキュメントの Download and Setup を参考にしています。

pyenv を使って Python 3.5.2 をインストール

Download and Setup の Requirements にある Python を準備します。 OS X (macOS) には元々 Python がインストールされていますが、3系を使うために別にインストールしてみます。Python のインストールには pyenv を利用することにしました。
元々 anyenv を利用していたため、anyenv を使って pyenv をインストール後、pyenv を使って python 3.5.2 をインストールしました。

% anyenv install pyenv
Cloning https://github.com/yyuu/pyenv.git...
Cloning into 'pyenv'...
remote: Counting objects: 14083, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 14083 (delta 0), reused 0 (delta 0), pack-reused 14075
Receiving objects: 100% (14083/14083), 2.48 MiB | 1.13 MiB/s, done.
Resolving deltas: 100% (9738/9738), done.
Checking connectivity... done.

Install pyenv succeeded!
Please reload your profile (exec $SHELL -l) or open a new session.

% exec $SHELL -l
% pyenv install 3.5.2
Downloading Python-3.5.2.tar.xz...
-> https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tar.xz
Installing Python-3.5.2...
patching file Lib/venv/scripts/posix/activate.fish

この環境では常に Python 3.5.2 を利用してもかまわないので、pyenv global で利用する Python のバージョンを指定しておきます。

% pyenv global 3.5.2
% exec $SHELL -l
% python -V
Python 3.5.2

Requirements には GPU 版を利用する場合の依存も書かれていますがひとまず利用しません。

Pip install による TensorFlow のインストール

Overview で TensorFlow のインストール方法には、既存の Python を利用したアプリケーションへの影響範囲などを考慮していくつかの選択肢が示されています。
今回は pyenv を使って専用の Python 環境をインストール済みであるため、既存の環境への影響は気にせずにすむので簡単な Pip Installation を選択します。

すでに pip はインストールされていますが、一応公式ドキュメントの手順通り easy_install を使っておきます。

% easy_install pip
% easy_install --upgrade six

次に環境毎に適切な URL を環境変数 TF_BINARY_URL にセットしておきます。今回は "Mac OS X, CPU only, Python 3.4 or 3.5" を選択しました。

% export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0rc2-py3-none-any.whl
% pip3 install --upgrade $TF_BINARY_URL
Collecting tensorflow==0.11.0rc2 from https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0rc2-py3-none-any.whl
  Downloading https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0rc2-py3-none-any.whl (35.5MB)
    100% |████████████████████████████████| 35.5MB 43kB/s 
Collecting numpy>=1.11.0 (from tensorflow==0.11.0rc2)
  Downloading numpy-1.11.2-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.9MB)
    100% |████████████████████████████████| 3.9MB 391kB/s 
Collecting protobuf==3.0.0 (from tensorflow==0.11.0rc2)
  Downloading protobuf-3.0.0-py2.py3-none-any.whl (342kB)
    100% |████████████████████████████████| 348kB 3.3MB/s 
Requirement already up-to-date: six>=1.10.0 in /Users/xxxxxx/.anyenv/envs/pyenv/versions/3.5.2/lib/python3.5/site-packages/six-1.10.0-py3.5.egg (from tensorflow==0.11.0rc2)
Collecting wheel>=0.26 (from tensorflow==0.11.0rc2)
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
    100% |████████████████████████████████| 71kB 5.8MB/s 
Collecting setuptools (from protobuf==3.0.0->tensorflow==0.11.0rc2)
  Downloading setuptools-28.7.1-py2.py3-none-any.whl (472kB)
    100% |████████████████████████████████| 481kB 2.3MB/s 
Installing collected packages: numpy, setuptools, protobuf, wheel, tensorflow
  Found existing installation: setuptools 20.10.1
    Uninstalling setuptools-20.10.1:
      Successfully uninstalled setuptools-20.10.1
Successfully installed numpy-1.11.2 protobuf-3.0.0 setuptools-28.7.1 tensorflow-0.11.0rc2 wheel-0.29.0
You are using pip version 8.1.1, however version 9.0.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

これをみると six も依存関係に含まれているので事前に upgrade する必要はなかったかもしれませんね。

それから最後に pip のバージョンの更新をうながすメッセージがあったのでついでに更新しておきました。

% pip install --upgrade pip
Collecting pip
  Downloading pip-9.0.0-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 1.0MB/s 
Installing collected packages: pip
  Found existing installation: pip 8.1.1
    Uninstalling pip-8.1.1:
      Successfully uninstalled pip-8.1.1
Successfully installed pip-9.0.0

動作確認

Run a TensorFlow demo model の方法で動作確認します。

% python
Python 3.5.2 (default, Nov  3 2016, 18:42:02) 
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
b'Hello, TensorFlow!'
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a + b))
42

'Hello, TensorFlow!' の表示がドキュメントと少々違いますが、これは Python 2.7 と 3.x 系で b'string' の表示が変わっているためだと思います。

ひとまずこれで準備完了しました。

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4