AttributeError: module 'tensorflow' has no attribute 'Session'
程序员文章站
2024-03-25 13:30:10
...
- 写老师布置的神经网络作业中,要求安装tensorflow,并且运行示例代码(使用with tf.Session()创建上下文)
- 我作为新手,本来想在Ubuntu上弄的,奈何电脑有点带不动虚拟机各种报bug。最后还是老老实实的在我的win10上安装了anaconda。官网:https://www.anaconda.com/。
- 最后在anaconda神器的图形界面上安装tensorflow
- 安装成功之后,开始运行老师给的示例代码:
import tensorflow as tf
hello=tf.constant('hello world!')
with tf.Session() as sess:
-
`print(sess.run(hello).decode())`
- 结果报错:AttributeError: module ‘tensorflow’ has no attribute ‘Session’
10.查了蛮久,一开始看的是英文的回答,半天没看懂,后来终于翻到国内网友的解答才明白。意思就是说更新的tensorflow已经删除了Session ,tf.Session()已过时,需要使用tf.compat.v1.Session()代替。即把上面第三行替换为
:with tf.compat.v1.Session() as sess:
- 现在运行代码就对了
推荐阅读
-
AttributeError: module 'tensorflow' has no attribute 'Session'
-
AttributeError: 'NoneType' object has no attribute 'find_all'
-
错误 AttributeError: 'NoneType' object has no attribute 'astype'
-
API项目——AttributeError: 'NoneType' object has no attribute 'decode'
-
在Django框架中偶遇报错:AttributeError: ‘str’ object has no attribute ‘decode’解决办法
-
AttributeError: ‘NoneType‘ object has no attribute ‘shape‘
-
Django 报错:‘AttributeError: ‘str‘ object has no attribute ‘decode‘‘
-
AttributeError: ‘NoneType‘ object has no attribute ‘name‘
-
【已解决】python-pip升级报错- AttributeError: 'NoneType' object has no attribute 'bytes'
-
AttributeError: ‘str‘ object has no attribute ‘decode‘ Python3