AttributeError:模块“numpy”没有属性“bool”。当导入glumpy时

问题描述 投票:0回答:1
>>> import glumpy
/home/mona/anaconda3/envs/clean-pvnet/lib/python3.10/site-packages/glumpy/gloo/variable.py:82: FutureWarning: In the future `np.bool` will be defined as the corresponding NumPy scalar.
  gl.GL_BOOL         : ( 1, gl.GL_BOOL,         np.bool),
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mona/anaconda3/envs/clean-pvnet/lib/python3.10/site-packages/glumpy/__init__.py", line 7, in <module>
    from . import app
  File "/home/mona/anaconda3/envs/clean-pvnet/lib/python3.10/site-packages/glumpy/app/__init__.py", line 23, in <module>
    from . console import Console
  File "/home/mona/anaconda3/envs/clean-pvnet/lib/python3.10/site-packages/glumpy/app/console.py", line 7, in <module>
    from glumpy import gl, glm, gloo
  File "/home/mona/anaconda3/envs/clean-pvnet/lib/python3.10/site-packages/glumpy/gloo/__init__.py", line 7, in <module>
    from . program import Program
  File "/home/mona/anaconda3/envs/clean-pvnet/lib/python3.10/site-packages/glumpy/gloo/program.py", line 16, in <module>
    from . variable import gl_typeinfo, Uniform, Attribute
  File "/home/mona/anaconda3/envs/clean-pvnet/lib/python3.10/site-packages/glumpy/gloo/variable.py", line 82, in <module>
    gl.GL_BOOL         : ( 1, gl.GL_BOOL,         np.bool),
  File "/home/mona/.local/lib/python3.10/site-packages/numpy/__init__.py", line 324, in __getattr__
    raise AttributeError(__former_attrs__[attr])
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.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations. Did you mean: 'bool_'?

我更改了以下文件行

(clean-pvnet) mona@ada:~/anaconda3/envs/clean-pvnet/lib/python3.10/site-packages/glumpy$ vi gloo/variable.py

bool        gl.GL_BOOL         1  gl.GL_BOOL         np.bool

bool        gl.GL_BOOL         1  gl.GL_BOOL         np.bool_

仍然是同样的错误。

尽管打开了新的终端选项卡并且

conda activate clean-pvnet
,但模块似乎并未重新加载。

python numpy conda glumpy
1个回答
0
投票

我只按照教程将其中一个

np.bool
转换为
np.bool_
。我搜索了所有这些并类似地转换了它们,错误消失了。

(clean-pvnet) mona@ada:~/anaconda3/envs/clean-pvnet/lib/python3.10/site-packages/glumpy$ rg np.bool_
gloo/variable.py
22:bool        gl.GL_BOOL         1  gl.GL_BOOL         np.bool_
23:bvec2       gl.GL_BOOL_VEC2    2  gl.GL_BOOL         np.bool_
24:bvec3       gl.GL_BOOL_VEC3    3  gl.GL_BOOL         np.bool_
25:bvec4       gl.GL_BOOL_VEC4    4  gl.GL_BOOL         np.bool_
82:    gl.GL_BOOL         : ( 1, gl.GL_BOOL,         np.bool_),
83:    gl.GL_BOOL_VEC2    : ( 2, gl.GL_BOOL,         np.bool_),
84:    gl.GL_BOOL_VEC3    : ( 3, gl.GL_BOOL,         np.bool_),
85:    gl.GL_BOOL_VEC4    : ( 4, gl.GL_BOOL,         np.bool_),

© www.soinside.com 2019 - 2024. All rights reserved.