美文网首页
macOS安装TensorFlow

macOS安装TensorFlow

作者: 许宏川 | 来源:发表于2019-01-08 23:18 被阅读29次

macOS自带python是2.7

安装pip

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python get-pip.py

查看pip版本

pip --version

输出:

pip 18.1 from /Library/Python/2.7/site-packages/pip (python 2.7)

安装virtualenv

sudo pip install virtualenv

查看virtualenv版本

virtualenv --version

输出:

16.2.0

用virtualenv创建python的虚拟环境

virtualenv --system-site-packages -p python2.7 ./venv

进入虚拟环境

source venv/bin/activate

离开虚拟环境是

deactivate

安装TensorFlow

pip install tensorflow

当前装的是1.12.0版本。

测试是否安装成功

python // 进入python环境
import tensorflow as tf // 导入包
exit() // 退出python环境

Hello TensorFlow

新建一个hello tensorflow.py

import tensorflow as tf
hello = tf.constant("Hello TensorFlow!")
sess = tf.Session()
print(sess.run(hello))

运行:

python hello\ tensorflow.py

输出:

2019-01-08 22:54:32.544683: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
Hello TensorFlow!

相关文章

网友评论

      本文标题:macOS安装TensorFlow

      本文链接:https://www.haomeiwen.com/subject/vkdirqtx.html