Reputation: 21
I’m using google colab with Python version 3.8.5 to run 'import mxnet as mx'. But it returns "module 'numpy' has no attribute 'bool'"
Actually this command worked really well last December(12.2023) and January(01.2024). So I don't know why it doesn't work today.
How can I fix this error? If anyone knows please help.
My code is :
from google.colab import drive
drive.mount('/content/drive')
!wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz
!tar xvfz Python-3.8.5.tgz
!Python-3.8.5/configure
!make
!sudo make install
!pip install torch==1.6.0+cpu torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
!pip install --upgrade gluoncv
!pip install --upgrade mxnet
import mxnet as mx
from mxnet import image
from mxnet.gluon.data.vision import transforms
import gluoncv
from gluoncv.utils.viz import get_color_pallete
import matplotlib.image as mpimg
from gluoncv.data.ade20k.segmentation import ADE20KSegmentation
from matplotlib import pyplot as plt
from gluoncv.data.transforms.presets.segmentation import test_transform
from google.colab import files
import pandas as pd
import numpy as np
import os
and this it results :
/usr/local/lib/python3.10/dist-packages/mxnet/numpy/utils.py:37: FutureWarning: In the future `np.bool` will be defined as the corresponding NumPy scalar.
bool = onp.bool
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-6-d07a1bcfa66c> in <cell line: 1>()
----> 1 import mxnet as mx
2 from mxnet import image
3 from mxnet.gluon.data.vision import transforms
4 import gluoncv
5
7 frames
/usr/local/lib/python3.10/dist-packages/numpy/__init__.py in __getattr__(attr)
317
318 if attr in __former_attrs__:
--> 319 raise AttributeError(__former_attrs__[attr])
320
321 if attr == 'testing':
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
Upvotes: 0
Views: 617
Reputation: 21
for people who have the same error, I solved the error like this.
by moving "import numpy~" before "import mxnet~" and adding "np.bool = np.bool_" between them.
import numpy as np
np.bool = np.bool_
import mxnet as mx
from mxnet import image
from mxnet.gluon.data.vision import transforms
import gluoncv
from gluoncv.utils.viz import get_color_pallete
import matplotlib.image as mpimg
from gluoncv.data.ade20k.segmentation import ADE20KSegmentation
from matplotlib import pyplot as plt
from gluoncv.data.transforms.presets.segmentation import test_transform
from google.colab import files
import pandas as pd
import os
Upvotes: 1
Reputation: 168834
Your pip install
commands don't pin any transitive dependencies, so back in December and January you will have gotten an older version of NumPy.
Looking at the source for NumPy, that message has been added in a commit that first shipped with NumPy 1.25.0.
Try downgrading NumPy to a version older than that, as a band-aid:
!pip install 'numpy<1.25.0'
Upvotes: 0