# 定义计算图
tens1 = tf.constant([1,2,3])# 创建一个会话
sess = tf.Session()# 使用这个创建好的会话来得到关心的运算的结果。比如可以调用 sess.run(result)
# 来得到张量result的取值
print(sess.run(tens1))#关闭会话是的本次运行中使用的到的志愿可以被释放
sess.close()

报错:

AttributeError: module 'tensorflow' has no attribute 'Session'

问题产生的原因:是tensorflow版本不同导致的,tensorflow版本2.0无法兼容版本1.0.
解决办法:sess = tf.compat.v1.Session()替换sess = tf.Session()
结果继续报错:

RuntimeError: The Session graph is empty.  Add operations to the graph before calling run().

解决办法:添加tf.compat.v1.disable_eager_execution()

#  保证sess.run()能够正常运行
tf.compat.v1.disable_eager_execution()# 定义计算图
tens1 = tf.constant([1,2,3])# 创建一个会话
sess = tf.compat.v1.Session()# 使用这个创建好的会话来得到关心的运算的结果。比如可以调用 sess.run(result)
# 来得到张量result的取值
print(sess.run(tens1))#关闭会话是的本次运行中使用的到的志愿可以被释放
sess.close()

运行成功,输出[1 2 3]

AttributeError: module 'tensorflow' has no attribute 'Session'.解决办法相关推荐

  1. AttributeError: module ‘tensorflow‘ has no attribute ‘Session‘错误解决

    AttributeError: module 'tensorflow' has no attribute 'Session'错误解决 根据网上教程安装tensorflow环境时,最后都会有个测试代码用 ...

  2. tensorflow2.0及以上版本在使用Session模块时报错:AttributeError: module ‘tensorflow‘ has no attribute ‘Session‘ 已解决

    tensorflow2.0版本及之后的版本在使用Session模块时报错:AttributeError: module 'tensorflow' has no attribute 'Session' ...

  3. AttributeError: module 'tensorflow' has no attribute 'Session'错误解决

    Ubuntu刚安装好Tensorflow以后运行 import tensorflow as tf tf.Session() 报错AttributeError: module 'tensorflow' ...

  4. Python异常:AttributeError: module ‘xxxx‘ has no attribute ‘open‘ 解决办法

    前言 小编一直在用 Python 做机器学习,项目折腾了这么久,常用的和不常用的组件都安装了一大堆,按理说不能出现少包的问题. 仔细检查了一下代码,果然发现了一个低级问题,引以为戒.分享出来,也希望新 ...

  5. AttributeError: module 'tensorflow' has no attribute 'Session'

    tf.Session()是旧版本的语法,如果要跑,加入下面代码 https://github.com/tensorflow/tensorflow/issues/34658 import tensorf ...

  6. AttributeError: module 'tensorflow' has no attribute 'random_normal'

    执行<TensorFlow实战Google深度学习框架(第2版)>only源代码 CH3 时如下语句报错 batch_size = 8 w1= tf.Variable(tf.random_ ...

  7. 成功解决AttributeError: module ‘tensorflow‘ has no attribute ‘get_variable‘

    成功解决AttributeError: module 'tensorflow' has no attribute 'get_variable' 目录 解决问题 解决思路 解决方法 解决问题 Attri ...

  8. 成功解决AttributeError: module tensorflow has no attribute placeholder

    成功解决AttributeError: module 'tensorflow' has no attribute 'placeholder' 目录 解决问题 解决思路 解决方法 解决问题 Attrib ...

  9. 成功解决AttributeError: module tensorflow has no attribute random_normal

    成功解决AttributeError: module 'tensorflow' has no attribute 'random_normal' 目录 解决问题 解决思路 解决方法 解决问题 Attr ...

最新文章

  1. 8.QML Qt Quick Controls 2中常用的界面形式——堆叠式界面(StackView)
  2. c语言中指,浅析C语言中指与数组.doc
  3. Observe rainy world
  4. python笔记1-准确掌握列表和元组
  5. 深入浅出Linux设备驱动编程--复杂设备驱动
  6. Struts2.3.1.2安装
  7. Android仿58同城Loading View
  8. 小米笔记本pro黑苹果原厂intel蓝牙亲测可用!!
  9. [速记] 网络安全复习——选择题汇总
  10. 计算机系统文件命名规则,Windows10系统怎样自定义副本文件默认命名规则
  11. KK集团5年估值200亿,新零售还好做吗?
  12. 青少年软件编程(Python)等级考试试卷一级(判断题)2021-9
  13. 问题服务器防火墙的选择
  14. 用 UrlSchemes 实现调用应用并传参
  15. [iOS]ARC下循环引用的问题
  16. 计算机如何添加新用户,笔记本电脑怎么样快速添加新用户帐号
  17. Netty空闲检测之写空闲
  18. 消息中间件MQ及ActiveMQ介绍
  19. [最小路径覆盖]拦截导弹
  20. 19年就业形势怎么样

热门文章

  1. ElasticSearch的scroll分批查询
  2. 安全运营中心(SOC)从这里开始(一)
  3. 上位机与s7-200通讯控制伺服电机
  4. 减法公式运算法则_加减乘除运算法则
  5. os.listdir(path)
  6. wifi吞吐量测试环境搭建和mifi的wifi吞吐量测试
  7. 机器学习入门的书单(数据挖掘、模式识别等一样)转
  8. 让男生成熟的十部电影zt
  9. 关于数据安全及保密(基于大数据板块的整理)
  10. 八大排序 - (详解)