Friday, October 28, 2016

Deep Learning : Tensorflow installation on MacOS

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#on-macosx-

Operation not permitted

If, despite using sudo, you encounter an error like:
...
Installing collected packages: setuptools, protobuf, wheel, numpy, tensorflow
Found existing installation: setuptools 1.1.6
Uninstalling setuptools-1.1.6:
Exception:
...
[Errno 1] Operation not permitted: '/tmp/pip-a1DXRT-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib'
Solution: Add an --ignore-installed flag to the pip command.
sudo easy_install pip

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0rc1-py2-none-any.whl

sudo pip install --upgrade $TF_BINARY_URL --ignore-installed


$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/tensorflow/__init__.py", line 23, in <module>
    from tensorflow.python import *
  File "/Library/Python/2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
ImportError: numpy.core.multiarray failed to import

>>> 


$ sudo easy_install numpy
Password:
Searching for numpy
Best match: numpy 1.11.2
Adding numpy 1.11.2 to easy-install.pth file

Using /Library/Python/2.7/site-packages
Processing dependencies for numpy
Finished processing dependencies for numpy
Jungshihs-MacBook-Pro-2:~ lo$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow

>>> 

Python 3

brew install python3
# 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
sudo 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 38kB/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 296kB/s 
Collecting six>=1.10.0 (from tensorflow==0.11.0rc2)
  Downloading six-1.10.0-py2.py3-none-any.whl
Collecting protobuf==3.0.0 (from tensorflow==0.11.0rc2)
  Downloading protobuf-3.0.0-py2.py3-none-any.whl (342kB)
    100% |████████████████████████████████| 348kB 1.8MB/s 
Collecting wheel>=0.26 (from tensorflow==0.11.0rc2)
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
    100% |████████████████████████████████| 71kB 1.0MB/s 
Collecting setuptools (from protobuf==3.0.0->tensorflow==0.11.0rc2)
  Downloading setuptools-28.8.0-py2.py3-none-any.whl (472kB)
    100% |████████████████████████████████| 481kB 1.6MB/s 
Installing collected packages: numpy, six, 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.8.0 six-1.10.0 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.
Jungshihs-MacBook-Pro-2:~ lo$ python3
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow

>>> 


git clone -b r0.11 https://github.com/tensorflow/tensorflow.git 
cd tensorflow/tensorflow/examples/tutorials/mnist

modify input_data.py
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('MNIST_data', one_hot=True)

$ python3 mnist_softmax.py --data_dir MNIST_data
Extracting MNIST_data/train-images-idx3-ubyte.gz
Extracting MNIST_data/train-labels-idx1-ubyte.gz
Extracting MNIST_data/t10k-images-idx3-ubyte.gz
Extracting MNIST_data/t10k-labels-idx1-ubyte.gz
0.9179





No comments:

Post a Comment