Python 从0开始的小萝卜特学习之旅
1、Tensorflow安装,使用教程
-
参考知乎“Python Tensorflow安装,使用教程”,链接https://zhuanlan.zhihu.com/p/56210706。
注意:“3,安装完成Anaconda,进行环境变量的测试”,貌似因为自己没有按照步骤(3)(4)来执行,即“安装python版本(建议跟我的一样3.5.2):conda create --name tensorflow1 python=3.5.2”,而是直接采用“pip install tensorflow”进行安装,所以安装完激活tensorflow的环境时,是输入“activate tensorflow”,少了个1,看来根据网上教程来,不能东拼西凑啊。
-
到“Tensorflow使用”节,按照步骤一步一步来,但到最后“(4)开始编写一段代码来测试”时
,输入又弹出问题,百度了下问题,找到了另一篇文章:博客网上“tensorflow使用Session模块时报错:AttributeError: module ‘tensorflow’ has no attribute ‘Session’,已解决”,链接为https://www.cnblogs.com/123456www/p/12584427.html。应该是我安装的tensorflow版本中的确没有Session这个属性,看来还是最开始安装tensorflow埋下的坑。按照这篇文章的方法代码,终于成功跑完了测试代码。附上修改后的测试代码。还有很多不太会的地方。再接再厉!
tf.compat.v1.disable_eager_execution()
#import tensorflow as tf
import tensorflow.compat.v1 as tf
import os
xiaotuanzi = tf.constant('xiaotuanzi,爱你')
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
#sess = tf.Session()
sess = tf.compat.v1.Session()
value = sess.run(xiaotuanzi).decode('utf-8')
print(value)



