新本子一片空白,需要用tensorflow跑结果。本子自带python2点版本,现在需要安装python3、pip、tensorflow,安装方法查了很多种,用的homedrew安装的,不得不说,很省事,很方便。
1、查看版本:python -V (V大写),显示的是安装的版本类型。(要用python3的话,就是python3 -V)
2、安装homedrew,这个真心方便,https://brew.sh,这个界面点进去,复制:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
到终端,然后计算机自动下载完成。
3、安装python3:输入命令:brew install python3 (此部操作同时下载pip。)
4、安装tensorflow: pip3 install tensorflow 。
5、顺利的话,没有问题了就。
测试安装:1、进入python3,输入:python3
2、import tensorflow as tf
- node1 = tf.constant(3.0, dtype=tf.float32)
- node2 = tf.constant(4.0)# also tf.float32 implicitly
- print(node1, node2)
- Tensor("Const:0", shape=(), dtype=float32) Tensor("Const_1:0",shape=(), dtype=float32)
- sess = tf.Session()
- print(sess.run([node1, node2]))
- node3 = tf.add(node1, node2)
- print("node3:", node3)
- print("sess.run(node3):", sess.run(node3))
结果出来是:
- node3:Tensor("Add:0", shape=(), dtype=float32)
- sess.run(node3):7.0
说明安装成功!
参考文献:https://blog.csdn.net/lengguoxing/article/details/78456279
https://www.cnblogs.com/i-am-lvjiazhen/p/6264354.html