TensorFlow+TFLearn > Jupyter Notebook on Mac OS X with Python 3.6@2017.11.25

Mac OS X にTensorFlow+TFLearnをインストール:
——————————-
色々と悪戦苦闘ののちに、ようやく理解できてきたこと:

とにかくPythonの環境設定を行うこと。
まずは、Anaconda Navigator画面のCreate+ボタンで、python 3.6を指定して、Python36という環境名を作成
screen_Create

screen_anaconda3
するとTerminalで、anaconda3/env/にPython36というフォルダができていることがわかる。
envs $ ls
Chap3.ipynb Python36 graphviz
Python35 Untitled.ipynb tfbook
envs $ cd Python36

このPython環境を以下のようにアクティベート
$ source activate Python36
(Python36) $ python -V
Python 3.6.3 :: Anaconda, Inc.
Python 3.6.3がインストールされていることがわかる。

(Python36) $ python
Python 3.6.3 |Anaconda, Inc.| (default, Nov 8 2017, 18:10:31)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import tensorflow
Traceback (most recent call last):
File ““, line 1, in
ModuleNotFoundError: No module named ‘tensorflow’
>>> exit()
でTensorFlowが、インストールされていないことがわかる。

そこで、
(Python36) $ conda install tensorflow
Fetching package metadata ………..
Solving package specifications: .

Package plan for installation in environment /Users/*****/anaconda3/envs/Python36:

The following NEW packages will be INSTALLED:

intel-openmp: 2018.0.0-h8158457_8
libgfortran: 3.0.1-h93005f0_2
libprotobuf: 3.4.1-h326466f_0
mkl: 2018.0.1-hfbd8650_4
numpy: 1.12.1-py36h8871d66_1
protobuf: 3.4.1-py36h314970b_0
six: 1.11.0-py36h0e22d5e_1
tensorflow: 1.1.0-np112py36_0
werkzeug: 0.12.2-py36h168efa1_0

Proceed ([y]/n)? y

numpy-1.12.1-p 100% |#########################| Time: 0:00:02 1.57 MB/s
six-1.11.0-py3 100% |#########################| Time: 0:00:00 1.86 MB/s
werkzeug-0.12. 100% |#########################| Time: 0:00:00 1.99 MB/s
protobuf-3.4.1 100% |#########################| Time: 0:00:00 2.44 MB/s
tensorflow-1.1 100% |#########################| Time: 0:00:10 2.40 MB/s
(Python36) $ pip install -U –no-deps tflearn
Collecting tflearn
Installing collected packages: tflearn
Successfully installed tflearn-0.3.2
(Python36) $ python
Python 3.6.3 |Anaconda, Inc.| (default, Nov 8 2017, 18:10:31)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import tensorflow
>>> import tflearn
hdf5 is not supported on this machine (please install/reinstall h5py for optimal experience)
Traceback (most recent call last):
File ““, line 1, in
File “/Users/******/anaconda3/envs/Python36/lib/python3.6/site-packages/tflearn/__init__.py”, line 61, in
from . import datasets
File “/Users/******/anaconda3/envs/Python36/lib/python3.6/site-packages/tflearn/datasets/__init__.py”, line 1, in
from . import cifar10
File “/Users/*****/anaconda3/envs/Python36/lib/python3.6/site-packages/tflearn/datasets/cifar10.py”, line 16, in
from ..data_utils import to_categorical
File “/Users/*****/anaconda3/envs/Python36/lib/python3.6/site-packages/tflearn/data_utils.py”, line 7, in
from PIL import Image
ModuleNotFoundError: No module named ‘PIL’
>>> exit()

TensorFlowはインストールされたが、PILがインストールされていない。

(Python36) $ pip install PIL
Collecting PIL
Could not find a version that satisfies the requirement PIL (from versions: )
No matching distribution found for PIL

エラーが出たので、ここでは、PILではなくて、pillowをインストールする。
(Python36) $ pip install pillow
Collecting pillow
Using cached Pillow-4.3.0-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting olefile (from pillow)
Installing collected packages: olefile, pillow
Successfully installed olefile-0.44 pillow-4.3.0
(Python36) MacBook-Pro-5:Python36 teijisw$ python
Python 3.6.3 |Anaconda, Inc.| (default, Nov 8 2017, 18:10:31)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import tensorflow
>>> import tflearn
hdf5 is not supported on this machine (please install/reinstall h5py for optimal experience)
Scipy not supported!
>>> exit()

Scipyがインストールされてない。

(Python36) $ pip install scipy
Collecting scipy
Using cached scipy-1.0.0-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Requirement already satisfied: numpy>=1.8.2 in ./lib/python3.6/site-packages (from scipy)
Installing collected packages: scipy
Successfully installed scipy-1.0.0
(Python36) $ python
Python 3.6.3 |Anaconda, Inc.| (default, Nov 8 2017, 18:10:31)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import tensorflow
>>> import tflearn
hdf5 is not supported on this machine (please install/reinstall h5py for optimal experience)
>>> exit()

hdf5がサポートされていない。
(Python36) $ pip install h5py
Collecting h5py
Using cached h5py-2.7.1-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Requirement already satisfied: six in ./lib/python3.6/site-packages (from h5py)
Requirement already satisfied: numpy>=1.7 in ./lib/python3.6/site-packages (from h5py)
Installing collected packages: h5py
Successfully installed h5py-2.7.1
(Python36) $ python
Python 3.6.3 |Anaconda, Inc.| (default, Nov 8 2017, 18:10:31)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import tensorflow
>>> import tflearn
>>> exit()
で無事にTensorFlowとTFLearnがインストールされた!

(Python36) $ jupyter notebook
[I 23:40:26.449 NotebookApp] The port 8888 is already in use, trying another port.
[I 23:40:26.450 NotebookApp] The port 8889 is already in use, trying another port.
[I 23:40:26.495 NotebookApp] JupyterLab alpha preview extension loaded from /Users/******/anaconda3/lib/python3.6/site-packages/jupyterlab
JupyterLab v0.27.0
………………..

The following NEW packages will be INSTALLED:

appnope: 0.1.0-py36hf537a9a_0
bleach: 2.0.0-py36h8fcea71_0
dbus: 1.10.22-h50d9ad6_0
decorator: 4.1.2-py36h69a1b52_0
entrypoints: 0.2.3-py36hd81d71f_2
expat: 2.2.5-hb8e80ba_0
gettext: 0.19.8.1-h15daf44_3
glib: 2.53.6-h33f6a65_2
html5lib: 0.999999999-py36h79312fd_0
icu: 58.2-h4b95b61_1
ipykernel: 4.6.1-py36h3208c25_0
ipython: 6.2.1-py36h3dda519_1
ipython_genutils: 0.2.0-py36h241746c_0
ipywidgets: 7.0.5-py36h5142716_0
jedi: 0.10.2-py36h6325097_0
jinja2: 2.9.6-py36hde4beb4_1
jpeg: 9b-he5867d9_2
jsonschema: 2.6.0-py36hb385e00_0
jupyter: 1.0.0-py36h598a6cc_0
jupyter_client: 5.1.0-py36hf6c435f_0
jupyter_console: 5.2.0-py36hccf5b1c_1
jupyter_core: 4.4.0-py36h79cf704_0
libiconv: 1.15-hdd342a3_7
libpng: 1.6.32-hd1e8b91_4
libsodium: 1.0.15-hd9e47c5_0
markupsafe: 1.0-py36h3a1e703_1

Proceed ([y]/n)? y

appnope-0.1.0- 100% |#########################| Time: 0:00:00 123.68 kB/s
decorator-4.1. 100% |#########################| Time: 0:00:00 794.03 kB/s
entrypoints-0. 100% |#########################| Time: 0:00:00 871.50 kB/s
ipython_genuti 100% |#########################| Time: 0:00:00 514.39 kB/s
jedi-0.10.2-py 100% |#########################| Time: 0:00:00 544.17 kB/s
markupsafe-1.0 100% |#########################| Time: 0:00:00 15.85 MB/s
mistune-0.8.1- 100% |#########################| Time: 0:00:00 1.14 MB/s
………………..

If this is your first install of dbus, automatically load on login with:
mkdir -p ~/Library/LaunchAgents
cp /Users/*****/anaconda3/envs/Python36/org.freedesktop.dbus-session.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/org.freedesktop.dbus-session.plist

If this is an upgrade and you already have the org.freedesktop.dbus-session.plist loaded:
launchctl unload -w ~/Library/LaunchAgents/org.freedesktop.dbus-session.plist
cp /Users/*****/anaconda3/envs/Python36/org.freedesktop.dbus-session.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/org.freedesktop.dbus-session.plist

———————————
Anaconda NavigatorのEnvironmentのPython36に、Open with Jupyter Notebookが選択できるようになっている。
———————————
Mac OS X 10.12.6 Sierra に Python 3.6.3 + TensorFlowとTFLearnのインストールに悪戦苦闘したが、ポイントは,
Anaconda3のEnvironmentsから、Create+ボタンで、Python 3.6を選んで環境を例えばPython36というような名前で生成する。
Terminalから、anaconda3/env/のフォルダにPython36フォルダができているので、$source activate Python36で環境内に入り、

$source activate Python36
(Python36) $conda install tensorflow
(Python36) $ pip install -U –no-deps tflearn
(Python36) $ pip install pillow
(Python36) $ pip install scipy
(Python36) $ pip install h5py
(Python36) $ jupyter notebook

Jupter Notebookの右上のNewボタンから、Terminalを立ち上げて、MNISTデータ・セットをダウンロードするためのディレクトリを予め作成しておく。
$mkdir data
$cd data
$mkdir mnist
———————————
これで、Anaconda3->Anaconda Navigator->Pytoh361->Jupyter NotebookでTensorFlow+TFlearnが使用可能となった! 
screen-jupyter
———————————
インストール悪銭苦闘の原因は、Anaconda3でPythonをインストールしたのに、コマンドラインで、別のPython環境を作成してしまったこと。Anaconda3でpython環境をインストールして、そこからJupyter Notebookを立ち上げて、学習する場合、Anaconda3 Navigatorの中で、そのPython環境設定を設定して、それをTerminalでアクティベートして、TensorFLowやTFLearnをインストールしていかないと、ばらばらとAnaconda3外のもともとのOSのPythonや、追加されたPythonに対して、TensorFlowがインストールされて、結果、Anacondaから立ち上げるJupyter Notebookと無関係となり、エラーがでる。