-
安装homebrew
homebrew是Mac端的一个软件包管理系统,通过它可以很方便地通过控制台命令安装程序。打开终端,输入(把下面的直接复制就行了):
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" -
用homedrew安装python
用homedrew安装python只要一行命令,然后等着就好了:
brew install python
- 安装pip
最终TensorFlow还是通过pip来安装的,所以先安装pip。pip的版本是根据python版本来的。
python2.7:
sudo easy_install pip
sudo easy_install --upgrade six
python3:
sudo easy_install pip3
sudo easy_install --upgrade six
- 引入TensorFlow的正确版本的URL
这里要根据自己的python版本来选择对应的TensorFlow的包。
需要查看python版本的话,在终端输入:python,然后回车,就会有了。
Mac OS X, CPU only, Python 2.7:
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0rc0-py2-none-any.whl
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.0rc0-py3-none-any.whl
- 用pip安装引入的TensorFlow
上面一步中把URL引入了,这一步用pip把该URL下的程序安装:
python2.7 / pip:
sudo pip install --upgrade $TF_BINARY_URL
python3 / pip3:
sudo pip3 install --upgrade $TF_BINARY_URL
- 第一个TensorFlow小demo
如果出现
DEPRECATION: Uninstalling a distutils installed project (numpy) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project
需要关闭sip
10.12系统处理方案:
1.关闭计算机
2.点击关闭后,按住shift+control+option+开机键两秒
3.按开机键,按住command+R进入使用工具界面
4.在菜单栏打开终端,输入csrutil disable 回车关闭sip功能
5.重启计算机终端重新执行安装命令
安装完成后,执行上述123,在第四步输入csrutil enable 回车 打开sip功能,因为sip会影响系统化安全问题
安装完毕,测试一下,是不是可以使用啦:
python
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
sess.run(hello)
输出结果:Hello, TensorFlow!
a = tf.constant(10)
b = tf.constant(32)
sess.run(a+b)
输出结果:42
网友评论