AttributeError: module ‘numpy‘ has no attribute ‘int‘

在使用numpy时,由于版本问题,np.int已被弃用并报错。为解决此问题,可以先卸载numpy,然后安装版本1.22。这样可以避免np.int的错误,因为它在NumPy1.20中开始被废弃。建议根据需要使用如np.int64或np.int32等明确的整数类型。
摘要由CSDN通过智能技术生成

在使用numpy的时候,会因为版本的原因,有些类型名称被弃用,导致报错。我们可以根据改变numpy的版本来解决这个报错问题。

如我在yolov5-5.0版本中numpy的问题出现如下的报错:

AttributeError: module 'numpy' has no attribute 'int'.`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:

百度翻译:

AttributeError:模块“numpy”没有属性“int”。
`np.int`是内置`int`的一个不推荐使用的别名。若要避免现有代码中出现此错误,请单独使用“int”。这样做不会修改任何行为,而且是安全的。在替换“np.int”时,您可能希望使用例如“np.int64”或“np.int32”来指定精度。如果您希望查看当前的使用情况,请查看发布说明链接以获取更多信息。
别名最初在NumPy 1.20中被弃用;有关更多详细信息和指南,请参阅以下原始发布说明:


解决方法:

在当前配置环境下先卸掉numpy,再将numpy版本改成1.22

pip uninstall numpy

pip install numpy==1.22

  • 18
    点赞
  • 48
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值