【DL-TensorFlow遇错】TensorFlow中遇错合集

一、AttributeError: module 'tensorflow' has no attribute 'placeholder'

错误原因

  • tensorflow版本问题:当前tensorflow版本为2.X,而tensorflow 2.0版本去掉了placeholder。tensorflow 1.*版本才有placeholder。

解决方案

  • “向后兼容”。这种做法可以在新版本的TensorFlow中仍然使用旧的API,确保旧代码的兼容性。

具体实现

  • 修改import tensorflow as tfimport tensorflow._api.v2.compat.v1 as tf

二、RuntimeError: tf.placeholder() is not compatible with eager execution.

错误原因

  • tf.placeholder()意味着被提供给会话,该会话在运行时从feed dict接收值并执行所需的操作。(也就是默认为急切运行,我们爆出这个错误说明不需要急切运行

解决方案
方式一:

  • tf.placeholder()被调用前添加tf.compat.v1.disable_eager_execution()

方式二:

import tensorflow._api.v2.compat.v1 as tf
tf.compat.v1.disable_eager_execution()

三、pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

报错信息:
在这里插入图片描述

  • pip._小贩urllib3.异常。读取超时错误:Http连接池(主机=‘files.pythonhosted.org’,端口=443):读取超时。

错误原因:

  • 使用pip安装模块的时候由于网络波动原因就会出现 pip._ vendor. urllib3. exceptions.ReadTimeoutError: HTTPSConnectionPool (host=’ files. pythonhosted.org’, port=443) : Read timed out.,小伙伴按照下面的命令使用国内的镜像地址安装即可!!!

问题解决:

  • 设置国内镜像源,设置超时(替换模块名称即可):
pip --default-timeout=100 install 模块名称 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com 
  • --trusted-host pypi.douban.com :表示信任豆瓣镜像地址

切换为其他国内镜像地址(替换命令中的网址即可):

  • 清华:https://pypi.tuna.tsinghua.edu.cn/simple
  • 阿里云:http://mirrors.aliyun.com/pypi/simple/
  • 中国科技大学:https://pypi.mirrors.ustc.edu.cn/simple/
  • 华中科技大学:http://pypi.hustunique.com/

四、Could not find a version that satisfies the requirement Levenshtein (from versions: none)

报错信息:
在这里插入图片描述
错误原因:

错误:找不到满足要求的版本<软件包>(来自版本:无)
错误:找不到匹配的<软件包>分布

错误解决:

  1. 首先确保输入软件包名称和版本号没有问题。

  2. 保证计算机连接网络。

  3. 更新pip:pip install --upgrade pip

  4. 更换pip源 :pip install <软甲包> -i https://pypi.tuna.tsinghua.edu.cn/simple/

  5. 更多请参考:解决参考

  • 17
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值