1. Python的下载及安装:
详细步骤和配置问题可以参考这篇文章: https://blog.csdn.net/alice_tl/article/details/767935902. 进入 terminal 终端
3. 进行pip安装和验证
pip3为python3的package 安装工具,命令如下:
此步骤为安装
$ sudo python3.5 get-pip.py
此步骤为验证pip3的存在及版本
$ pip3 –V
4. 安装tensorflow包及其他依赖的相关包
官方推荐用virtualenv方式安装tensorflow:https://www.tensorflow.org/install/install_mac#installing_with_virtualenv
a) 安装virtualenv$ sudo pip install --upgrade virtualenv
b) 创建python3独立虚拟环境
$ virtualenv -p python ~/tensorflow
$ cd tensorflow
$ source bin/activate
发现命令行提示符变成如下:(tensorflow)$
c) 在虚拟环境下,安装tensorflow及所需的package
$ pip3 install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.2.0-py3-none-any.whl
5. 验证环境是否搭建成功
(tensorflow)$ python >>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>> print(sess.run(hello))输出结果:
Hello, TensorFlow!
另一段:
C02Q9VN6FVH5:~ aa$ cd tensorflow C02Q9VN6FVH5:tensorflow aa$ source bin activate -bash: source: bin: is a directory C02Q9VN6FVH5:tensorflow aa$ source bin/activate (tensorflow) C02Q9VN6FVH5:tensorflow aa$ python Python 3.6.3 (v3.6.3:2c5fed86e0, Oct 3 2017, 00:32:08) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() 2018-04-16 18:50:12.183299: 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. 2018-04-16 18:50:12.183342: 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. 2018-04-16 18:50:12.183352: 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. 2018-04-16 18:50:12.183361: 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)) b'Hello, TensorFlow!' >>> import tensorflow as tf >>> hello=tf.constant("hello world") >>> a=tf.constant(60) >>> b=tf.constant(30) >>> sess=tf.Session() >>> print(sess.run(a))输出结果:
60