[最佳实践] 解决AttributeError: module ‘numpy‘ has no attribute ‘bool‘ 报错
·
报错
AttributeError: module 'numpy' has no attribute 'bool'.
`np.bool` was a deprecated alias for the builtin `bool`.
To avoid this error in existing code, use `bool` by itself.
Doing this will not modify any behavior and is safe.
If you specifically wanted the numpy scalar type, use `np.bool_` here.
原因
在numpy的1.24版本已经弃用了np.bool这个名称,取而代之的是np.bool_
解决办法
主要是新版本的问题,解决方法降级numpy
// 降级numpy
pip uninstall numpy
pip install numpy==1.23.5
测试
//测试降级后的numpy变量是否可用
import numpy as np
print(np.bool(True))# 不报错,有警告正常
更多推荐

所有评论(0)