Mac中安裝tensorflow

一:使用pip安裝Virtualenv

~/Giant/webRTC_xCode on release/2.9! 15:39:02

$ sudo pip install --upgrade virtualenv

Password:

The directory '/Users/along/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

You are using pip version 7.1.0, however version 9.0.1 is available.

You should consider upgrading via the 'pip install --upgrade pip' command.

The directory '/Users/along/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

Collecting virtualenv

  Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)

    100% |████████████████████████████████| 1.8MB 182kB/s

Installing collected packages: virtualenv

Successfully installed virtualenv-15.1.0

 

二:創建virtualenv環境到指定的目錄下:

~ 15:43:20

$ virtualenv --system-site-package ~/ATest/TFTest

New python executable in /Users/along/ATest/TFTest/bin/python

Installing setuptools, pip, wheel...done.

 

~ 15:43:34

$ ll ATest/TFTest

total 8

drwxr-xr-x  16 along  staff   544B 10 13 15:43 bin

drwxr-xr-x   3 along  staff   102B 10 13 15:43 include

drwxr-xr-x   3 along  staff   102B 10 13 15:43 lib

-rw-r--r--   1 along  staff    60B 10 13 15:43 pip-selfcheck.json

 

三:激活virtualenv環境:

~ 15:45:01

$ source ATest/TFTest/bin/activate

(TFTest) 

 

四:在virtualenv環境中安裝tensorflow

~ 15:47:58

$ pip install --upgrade tensorflow

Collecting tensorflow

 

  Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x10a78b410>: Failed to establish a new connection: [Errno 65] No route to host',)': /simple/tensorflow/

  Downloading tensorflow-1.3.0-cp27-cp27m-macosx_10_11_x86_64.whl (39.4MB)

    100% |████████████████████████████████| 39.4MB 26kB/s

Collecting protobuf>=3.3.0 (from tensorflow)

  Downloading protobuf-3.4.0-py2.py3-none-any.whl (375kB)

    100% |████████████████████████████████| 378kB 486kB/s

Collecting backports.weakref>=1.0rc1 (from tensorflow)

  Downloading backports.weakref-1.0.post1-py2.py3-none-any.whl

Requirement already up-to-date: wheel in ./ATest/TFTest/lib/python2.7/site-packages (from tensorflow)

Collecting tensorflow-tensorboard<0.2.0,>=0.1.0 (from tensorflow)

  Downloading tensorflow_tensorboard-0.1.8-py2-none-any.whl (1.6MB)

    100% |████████████████████████████████| 1.6MB 407kB/s

Collecting mock>=2.0.0 (from tensorflow)

  Downloading mock-2.0.0-py2.py3-none-any.whl (56kB)

    100% |████████████████████████████████| 61kB 842kB/s

Collecting numpy>=1.11.0 (from tensorflow)

  Downloading numpy-1.13.3-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (4.6MB)

    100% |████████████████████████████████| 4.6MB 177kB/s

Collecting six>=1.10.0 (from tensorflow)

  Downloading six-1.11.0-py2.py3-none-any.whl

Requirement already up-to-date: setuptools in ./ATest/TFTest/lib/python2.7/site-packages (from protobuf>=3.3.0->tensorflow)

Collecting bleach==1.5.0 (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow)

  Downloading bleach-1.5.0-py2.py3-none-any.whl

Collecting markdown>=2.6.8 (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow)

  Downloading Markdown-2.6.9.tar.gz (271kB)

    100% |████████████████████████████████| 276kB 623kB/s

Collecting html5lib==0.9999999 (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow)

  Downloading html5lib-0.9999999.tar.gz (889kB)

    100% |████████████████████████████████| 890kB 507kB/s

Collecting werkzeug>=0.11.10 (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow)

  Downloading Werkzeug-0.12.2-py2.py3-none-any.whl (312kB)

    100% |████████████████████████████████| 317kB 553kB/s

Collecting funcsigs>=1; python_version < "3.3" (from mock>=2.0.0->tensorflow)

  Downloading funcsigs-1.0.2-py2.py3-none-any.whl

Collecting pbr>=0.11 (from mock>=2.0.0->tensorflow)

  Downloading pbr-3.1.1-py2.py3-none-any.whl (99kB)

    100% |████████████████████████████████| 102kB 844kB/s

Building wheels for collected packages: markdown, html5lib

  Running setup.py bdist_wheel for markdown ... done

  Stored in directory: /Users/along/Library/Caches/pip/wheels/bf/46/10/c93e17ae86ae3b3a919c7b39dad3b5ccf09aeb066419e5c1e5

  Running setup.py bdist_wheel for html5lib ... done

  Stored in directory: /Users/along/Library/Caches/pip/wheels/6f/85/6c/56b8e1292c6214c4eb73b9dda50f53e8e977bf65989373c962

Successfully built markdown html5lib

Installing collected packages: six, protobuf, backports.weakref, html5lib, bleach, numpy, markdown, werkzeug, tensorflow-tensorboard, funcsigs, pbr, mock, tensorflow

  Found existing installation: six 1.4.1

    Not uninstalling six at /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python, outside environment /Users/along/ATest/TFTest

  Found existing installation: numpy 1.8.0rc1

    Not uninstalling numpy at /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python, outside environment /Users/along/ATest/TFTest

Successfully installed backports.weakref-1.0.post1 bleach-1.5.0 funcsigs-1.0.2 html5lib-0.9999999 markdown-2.6.9 mock-2.0.0 numpy-1.13.3 pbr-3.1.1 protobuf-3.4.0 six-1.11.0 tensorflow-1.3.0 tensorflow-tensorboard-0.1.8 werkzeug-0.12.2

(TFTest)

 

 

五:python shell中運行TensorFlow:

~ 15:52:29

$ 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 as tf

>>> hello = tf.constant('hello, TensorFlow!')

>>> sess = tf.Session()

2017-10-13 15:54:21.721091: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.

2017-10-13 15:54:21.721135: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.

2017-10-13 15:54:21.721140: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.

2017-10-13 15:54:21.721144: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.

>>> print sess.run(hello)

hello, TensorFlow!

>>> a = tf.constant(10)

>>> b = tf.constant(32)

>>> print sess.run(a+b)

42

 

六:使用腳本運行tensorflow

~/ATest 15:58:02

$ vim tfTest.py

 

import tensorflow as tf

hello = tf.constant('hello,Tensorflow')

sess = tf.Session()

print sess.run(hello)

a = tf.constant(10)

b = tf.constant(32)

print sess.run(a+b)

              

~/ATest 15:59:53

$ python tfTest.py

Traceback (most recent call last):

  File "tfTest.py", line 1, in <module>

    import tensorflow as tf

ImportError: No module named tensorflow

 

~/ATest 16:00:01

$ source TFTest/bin/activate

(TFTest)

~/ATest 16:01:12

$ python tfTest.py

2017-10-13 16:01:19.421796: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.

2017-10-13 16:01:19.421819: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.

2017-10-13 16:01:19.421824: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.

2017-10-13 16:01:19.421829: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.

hello,Tensorflow

42

(TFTest) 

 

 

 

 

官網需要翻牆:https://www.tensorflow.org/install/install_mac

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章