ほのぼのしたエンジニアのブログ

触った技術についてまとめていくブログです。

macでtensorflowやろうと思って戸惑った話

どうもShZgZです。
環境構築はやっぱり難しい。

今回は、macでtensorflowを触ってみようと思って環境構築してみる話です。

とりあえず、今回のこの記事で伝えたいことは、


2018/08/17現在、Python3.7でtensorflow試すのはかなり大変そう

ということ

丁度、触ってみようと思ってた人、環境構築で戸惑ってる人の参考になればと思います。
まず、Pythonのバージョンを確認してください!
(今の所、3.6なら大丈夫です)

環境:macOS High Sierra 10.13.4

ちゃっちゃとやっていきましょう。

因みにOfficialの方法試したけど、色々あって上手くいかなかったので今回の対応です。


Pythonのバージョンを3.6に下げる! 以上

本当に殆どコレに尽きます。
こちらも書いたので参考にどうぞ
shzgz.hatenablog.com


これでPythonのバージョンを3.6.6にしてから以下です。

$ pip install —upgrade pip virtualenv
$ python3 -m virtualenv {dir_name}
$ cd {dir_name}
$ source bin/activate
# 念のためバージョンを確認
$ python —version
3.6.6
$ pip install —upgrade tensorflow matplotlib

無事成功
(3.7で色々試して結局ダメだったけど3.6に下げたら全部すごいすんなりいった。長かった)


最後の確認

$ python
>>> import tensorflow
>>>

成功。。。しかし、

>>> import matplotlib.pyplot

を実行したところ

RuntimeError: Python is not installed as a framework. 
The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. 
See the Python documentation for more information on installing Python as a framework on Mac OS X. 
Please either reinstall Python as a framework, or try one of the other backends. 
If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. 
See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.

(長かったので所々改行)


aggの設定周りっぽかったので、
~/.matplotlib
にmatplotlibrcファイルを作成し、
~/.matplotlib/matplotlibrc

backend : TkAgg
>>> import matplotlib.pyplot

成功!!!


今の所はこんな感じでできました。
バージョン調べることの大切さ

でわー