If install with virtualenv
(https://www.tensorflow.org/install/install_mac)
During installation, "$ pip install --upgrade tensorflow" must be done
'within' virtualenv.
It worked well.
But, warning messgaes that SSE4 support is possible in this machine.
I found that installation from source would enable this support,
removing the warning and enhancing the performance.
If install from source with Python2.7
(https://www.tensorflow.org/install/install_sources#PrepareMac)
- prepare environment for Mac OS
First, bazel is installed. And then tensorflow python dependencies.
- configure
During configuration, everything is default except "location of python"
which is to be "/usr/bin/python2.7" specified in the guide.
That is, just push 'enter's after that.
- build pip package
bazel build is used to make a script.
Running this script builds a .whl file in /tmp/tensorflow_pkg
The building process took about 30 minuets.
- install pip package and error
An error occurs as follows:
Found existing installation: numpy 1.8.0rc1
DEPRECATION: ...
Uninstalling numpy-1.8.0rc1:
Exception:
...
OSError: [Errno 1] Operation not permitted: '/tmp/pip-mkEjV1-uninstall/S
ystem/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/numpy-1.8.0rc1-py2.7.egg-info'
According to https://github.com/tensorflow/tensorflow/issues/6331
this error occurs due to the confusion with the global python in machine
and homebrew or virtualenv would solve the problem.
I chose virtualenv.
- install pip package
$ mv tensorflow tensorflowBuilding
// to make the virtualenv as tensorflow
$ virtualenv tensorflow
$ cd tensorflow
$ source bin/activate // entering into virtualenv
(tensorflow) $ pip install /tmp/tensorflow_pkg/tensorflow-1.0.1-cp27-cp2
7m-macosx_10_12_intel.whl
- test
$ python // entering into python
>>>
python prompt (>>>) appears.
Now I validated the tensorflow according to the guide.
(a simple 4-line test)
>>> quit() // or crtl-d; leaving python
And I made a directory ~/tensorflow/test1/ and made a test python file
~/tensorflow/test1/tst.py
(https://www.tensorflow.org/get_started/get_started)
$ python test1/tst.py
Output of tst.py appears.
If install from source with Python3.5
First download and install Python3.5 which is installed automatically
in "local" directories such as:
/usr/local/bin/
(not /usr/bin/) (pip3 is also installed)
/Library/Frameworks/Python.framework/Versions/3.5/
(not /System/Library/Frameworks/Python.framework/Versions/)
All the same with the case with Python2.7 except:
- prepare environment for Mac Os
Installing python dependencies, use pip3 instead of pip
- configure
location of python is to be "/usr/local/bin/python3.5"
- install pip package and error
I installed with pip3.
$ pip3 install /tmp/tensorflow_pkg/tensorflow-1.1.0-cp35-cp35m-macosx_10
_6_intel.whl
Installation is done successfully.
But an error occurs when test as follows:
$ python3
>>> import tensorflow as tf
...
ImportError: No module named 'tensorflow.python.pywrap_tensorflow_intern
al'
- install pip package with virtualenv
Reinstall virtualenv with pip3 as follow:
(pip3 is already installed with python3 in /usr/local/bin/)
$ pip3 install --upgrade virtualenv
/usr/local/bin/virtualenv is installed.
Now make a virtualenv named "tf".
$ virtualenv --system-site-packages -p python3 tf
$ source ~/tf/bin/activate // to activate virtualenv
(tf) $ pip3 install /tmp/tensorflow_pkg/tensorflow-1.1.0-cp35-cp35m-maco
sx_10_6_intel.whl
- test
$ python3 // entering python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
b'Hello, TensorFlow!'
>>> quit() // leaving python
And then, a longer test:
$ python3 ~/tf/workspace/mnist/mnist1.py
Output of mnist1.py appears.
Tensorboard usage:
tensorboard command is not working since tensorflow is not installed
when installed from source. So, use:
$ python3 -m tensorflow.tensorboard --logdir=path/to/log-dir
(ex. python3 -m tensorflow.tensorboard --logdir=mnist5-model/train)
cf. tensorboard is in ~/tensorflowBuilding/tensorflow/tensorboard/
pyinstaller
$ which pyinstaller // to check if installed already
$ pip3 install pyinstaller
$ which pyinstaller
/Library/Frameworks/Python.framework/Versions/3.5/bin/pyinstaller
$ pyinstaller test.py
$ dist/test/test
Output appears
At first, I guessed that pyinstaller should be done in virtualenv, but
running pyinstaller and running the executables can be done
either inside or outside virtualenv.
But for some .py files, there is error....
Note:
Strangely, tensorflow is now working with python3 outside virtualenv
a few days after "If install from source with Python3.5"
I found that
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/
had already existed before I upgraded virtualenv.
Install static libraries for iOS as
~/tensorflowBuilding/tensorflow/contrib/makefile/gen/lib/libtensorflow-core.a
(https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/makefile)
- download source
$ cd ~/tensorflowBuilding // must be at root dir of repository
$ tensorflow/contrib/makefile/download_dependencies.sh
$ ls -F tensorflow/contrib/makefile/downloads
eigen/ gemmlowp/ googletest/ protobuf/ re2/
- Xcode command line tools are needed (included in Xcode 8.3 already)
- automake and libtool are needed
$ brew install automake // now as /usr/local/bin/automake
$ brew install libtool // needed even though libtool exists already
// now as /usr/local/bin/glibtool not to be confused with /usr/bin/libtool
$ tensorflow/contrib/makefile/build_all_ios.sh
Running iOS examples
- download the graph of inception5h for test from
https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip
as a directory ~/tf/workspace/iosTest/graphs/inception5h/
- copy
$ cp tf/workspace/iosTest/graphs/inception5h/* ~/tensorflowBuilding/tensorflow/contrib/ios_examples/simple/data
$ cp tf/workspace/iosTest/graphs/inception5h/* ~/tensorflowBuilding/tensorflow/contrib/ios_examples/camera/data
$ cp tf/workspace/iosTest/graphs/inception5h/* ~/tensorflowBuilding/tensorflow/contrib/ios_examples/benchmark/data
In Finder, go to ~/tensorflowBuilding/tensorflow/contrib/ios_examples/simple
and doublic click tf_ios_makefile_example.xcodeproj.
Then Xcode launches.
Build and run the example projects simple and benchmark on Simulator.
Project camera_example is not working on Simulator but on the real device.
Connect the iOS device and set the destination by selecting
Product > Destination > Device ...
But this resulted in signing error like
"none of your accounts are a member of ..."
Select the project camera_example in the left pane
> select CameraExample or camera_example in the right pane,
expanding sub-menu
> select CameraExample under Targets, showing tab menus
> select General tab
Change Bundle Identifier from "com.google.CameraExample" to random
string like "iosTestCamera".
Set Team as my own apple developer account.
Now, build again. And run.
The CameraExample icon appears in the device. Tap the icon.
But, this results in "neocella@gmail.com(...)" is not trusted..." error.
Then go to Settings > General > Device Management > select the account
> tap Trust "neocella@gmail.com"
Now. tap the icon again.
Note:
I moved ~/tf, ~/tensorflowBuilding, ~/tensorflowEtc
into ~/_toSave/_important/Tensorflow/
2018.8.6
Installing with pip3
Tried to update to version Tensorf.ow 1.9.0
This is for all users (not using virtualenv)
$ sudo pip3 install --up
TLS error
$ curl https://bootstrap.pypa.io/get-pip.py | python3 // to update pip3
$ sudo pip3 install --upgrade tensorflow==1.9.0grade tensorflow==1.9.0 // sudo needed
But during "python3 > import tensorflow as tf", "Illegal Instruction: 4" error.
I changed the owner to root from soh for all the files under /Library/Frameworks/Python.framework/Versions/3.5/
and deleted bin, lib, include, and pip-selfcheck.json under ~/_toSave/_important/Tensorflow/tf/ to no avail.
I uninstalled tensorflow by "sudo pip3 uninstall tensorflow" and reinstalled "sudo pip3 install tensorflow==1.3.0"
It works. The later versions are show some errors.
But, SSE4.2 warning.
It seems that enabling SSE4.2 results in speed up of > x2.
Let's install from source again.
$ cd _toSave/_important/Tensorflow/
$ git clone https://github.com/tensorflow/tensorflow
$ cd tensorflow
$ git checkout r1.3
$ ./configure
// input /usr/local/bin/python3, and default for the others
$ bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
$ sudo pip3 uninstall tensorflow // uninstall current tensorflow
$ sudo pip3 install /tmp/tensorflow_pkg/tensorflow-1.3.1-cp35-cp35m-macosx_10_6_intel.whl
$ python3 // "import tensorflow as tf" results in error.
// a comment by mkarliner in https://github.com/tensorflow/models/issues/1200 suggest to leave the directory
// ~/_toSave/_important/Tensorflow/tensorflow/ and it worked strangely.
$ cd
$ python3
2018.9.9
on a new iMac
install JDK 10.0.2, python 3.6.5 (3.7 conflicts while compiling) through browser download and with installer
install Bazel 0.16.1 through downloading and running script bazel-0.16.1-installer-darwin-x86_64.sh
according to tensor flow guide, sudo is used for some instructions, but I just didn't use.
$ pip3 install --upgrade pip
$ pip3 install six numpy wheel mock h5py
$ pip3 install keras_applications==1.0.5 --no-deps
$ pip3 install keras_preprocessing==1.0.3 --no-deps
$ cd ~/works/tf
$ git clone https://github.com/tensorflow/tensorflow
$ cd tensorflow
$ git checkout r1.10
$ ./configure
$ bazel build --config=mkl --config=opt //tensorflow/tools/pip_package:build_pip_package
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
$ pip3 install /tmp/tensorflow_pkg/tensorflow-1.10.1-cp36-cp36m-macosx_10_9_x86_64.whl
$ cd ~/works/tf
$ git clone https://github.com/keras-team/keras.git
$ cd keras
$ python3 setup.py install