macOS上に PyCall + TensorFlow 環境を作る

つまりポイントないからコマンド流すだけ

Anaconda

Command-Line Installer でインストールする Download Anaconda Now! | Continuum

TensorFlowのインストー

Installing TensorFlow on Mac OS X  |  TensorFlow

$ conda create -n tensorflow python=3.6

# 作った環境確認
$ conda info -e
tensorflow            /Users/hogefuga/anaconda3/envs/tensorflow
root              *  /Users/hogefuga/anaconda3

$ source activate tensorflow

# 作った環境に設定したPythonバージョンになってるか確認
(tensorflow) $ python --version
Python 3.6.2 :: Continuum Analytics, Inc.

$ pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.2.1-py3-none-any.whl

# インストールできてること確認
(tensorflow) $ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
b'Hello, TensorFlow!'

PyCallのインストー

Ruby-Pythonブリッジライブラリ「PyCall」を使ってRubyでデータ分析をしよう! (1/3):CodeZine(コードジン)

(tensorflow) $ gem install --pre pycall matplotlib

# pipそのものは、anacondaで環境作った時に既に入ってるのでインストールスキップできる

(tensorflow) $ pip install matplotlib numpy pandas seaborn

(tensorflow) $ irb
irb(main):004:0> require 'pycall'
=> true
irb(main):005:0> PyCall
=> PyCall
irb(main):015:0> module Py
irb(main):016:1> extend PyCall::Import
irb(main):017:1> pyimport :tensorflow, as: :tf
irb(main):018:1> end
=> :tf
irb(main):019:0> Py.tf
=> <module 'tensorflow' from '/Users/hogefuga/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/__init__.py'>
irb(main):020:0> Py.tf.constant.('Hello, Tensorflow!')
=> <tf.Tensor 'Const:0' shape=() dtype=string>
irb(main):021:0> hello = Py.tf.constant.('Hello, Tensorflow!')
=> <tf.Tensor 'Const_1:0' shape=() dtype=string>
irb(main):022:0> sess = Py.tf.Session.()
=> <tensorflow.python.client.session.Session object at 0x1046ff470>
irb(main):023:0> sess.run.(hello)
=> "Hello, Tensorflow!"