如何解决AttributeError:模块'numpy'没有属性'bool'?

kknvjkwl  于 2022-12-23  发布在  其他
关注(0)|答案(1)|浏览(6616)

我使用的是conda环境,Python版本为3.9.7,pip 22.3.1,numpy 1.24.0,gluoncv 0.10.5.post0,mxnet 1.7.0.post2
from gluoncv import data, utils给出误差:

C:\Users\std\anaconda3\envs\myenv\lib\site-packages\mxnet\numpy\utils.py:37: FutureWarning: In the future `np.bool` will be defined as the corresponding NumPy scalar.  (This may have returned Python scalars in past versions
  bool = onp.bool

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[1], line 3
      1 #import cv2
      2 #import os
----> 3 from gluoncv import data, utils #does not work

File ~\anaconda3\envs\myenv\lib\site-packages\gluoncv\__init__.py:16
     14 _found_mxnet = _found_pytorch = False
     15 try:
---> 16     _require_mxnet_version('1.4.0', '2.0.0')
     17     from . import data
     18     from . import model_zoo

File ~\anaconda3\envs\myenv\lib\site-packages\gluoncv\check.py:6, in _require_mxnet_version(mx_version, max_mx_version)
      4 def _require_mxnet_version(mx_version, max_mx_version='2.0.0'):
      5     try:
----> 6         import mxnet as mx
      7         from distutils.version import LooseVersion
      8         if LooseVersion(mx.__version__) < LooseVersion(mx_version) or \
      9             LooseVersion(mx.__version__) >= LooseVersion(max_mx_version):

File ~\anaconda3\envs\myenv\lib\site-packages\mxnet\__init__.py:33
     30 # version info
     31 __version__ = base.__version__
---> 33 from . import contrib
     34 from . import ndarray
     35 from . import ndarray as nd

File ~\anaconda3\envs\myenv\lib\site-packages\mxnet\contrib\__init__.py:30
     27 from . import autograd
     28 from . import tensorboard
---> 30 from . import text
     31 from . import onnx
     32 from . import io

File ~\anaconda3\envs\myenv\lib\site-packages\mxnet\contrib\text\__init__.py:23
     21 from . import utils
     22 from . import vocab
---> 23 from . import embedding

File ~\anaconda3\envs\myenv\lib\site-packages\mxnet\contrib\text\embedding.py:36
     34 from ... import base
     35 from ...util import is_np_array
---> 36 from ... import numpy as _mx_np
     37 from ... import numpy_extension as _mx_npx
     40 def register(embedding_cls):

File ~\anaconda3\envs\myenv\lib\site-packages\mxnet\numpy\__init__.py:23
     21 from . import random
     22 from . import linalg
---> 23 from .multiarray import *  # pylint: disable=wildcard-import
     24 from . import _op
     25 from . import _register

File ~\anaconda3\envs\myenv\lib\site-packages\mxnet\numpy\multiarray.py:47
     45 from ..ndarray.numpy import _internal as _npi
     46 from ..ndarray.ndarray import _storage_type, from_numpy
---> 47 from .utils import _get_np_op
     48 from .fallback import *  # pylint: disable=wildcard-import,unused-wildcard-import
     49 from . import fallback

File ~\anaconda3\envs\myenv\lib\site-packages\mxnet\numpy\utils.py:37
     35 int64 = onp.int64
     36 bool_ = onp.bool_
---> 37 bool = onp.bool
     39 pi = onp.pi
     40 inf = onp.inf

File ~\anaconda3\envs\myenv\lib\site-packages\numpy\__init__.py:284, in __getattr__(attr)
    281     from .testing import Tester
    282     return Tester
--> 284 raise AttributeError("module {!r} has no attribute "
    285                      "{!r}".format(__name__, attr))

AttributeError: module 'numpy' has no attribute 'bool'
hfwmuf9z

hfwmuf9z1#

这在mxnet中无处不在,它在v2.0.0候选版本中(所以,出血边缘),与您正在使用的版本1.7.0中相同。
我不太清楚的是,这是什么时候在numpy中消失的。它没有列在current scalar types中。但是,让我们跳回到2019年,numpy1.18版本,在您正在使用的mxnet版本发布之前-在这里。它甚至不是一个类型!
这里最令人困惑的是,它是在utils.py中,你可能会认为这样的模块会因为这个问题而崩溃,因为这将是一个核心模块...但它不是。我不知道我错过了什么,但可能值得在他们的github上提出。

相关问题