AttributeError: module 'numpy' has no attribute 'bool'. when importing glumpy

846 views Asked by At
>>> 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_'?

I changed the following file line (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

to

bool gl.GL_BOOL 1 gl.GL_BOOL np.bool_

and still same error.

It seems the module is not being reloaded despite opening a new terminal tab and conda activate clean-pvnet.

2

There are 2 answers

2
Mona Jalal On BEST ANSWER

I only converted one of the np.bools to np.bool_ following a tutorial. I searched for all of them and converted them similarly and error is gone.

(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_),

0
FlyingTeller On

UPDATE

glumpy has been updated, so just do

pip install glumpy==1.2.1

OLD ANSWER

The underlying issue is that glumpy just has numpy in its requirements, while in reality, it should be numpy<1.24, so one solution can also be to just downgrade numpy. Depending on if you installed it by conda/pip, use

pip/conda install numpy<1.24