# module 'numpy' has no attribute 'long'
# 问题
import numpy as np
np.long(19)
执行上面代码的时候报错,
<stdin>:1: FutureWarning: In the future `np.long` will be defined as the corresponding NumPy scalar.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/media/lx/data/sw/anaconda3/envs/mm/lib/python3.8/site-packages/numpy/__init__.py", line 320, in __getattr__
raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'long'
# 解决办法
查看本地numpy
版本,
pip show numpy
# Name: numpy
# Version: 1.24.4
# Summary: Fundamental package for array computing in Python
# Home-page: https://www.numpy.org
# Author: Travis E. Oliphant et al.
# Author-email:
# License: BSD-3-Clause
# Location: /media/lx/data/sw/anaconda3/envs/mm/lib/python3.8/site-packages
# Requires:
# Required-by: torchvision
本地numpy
版本是1.24.4
,numpy.long
方法自1.20
版本就标记为deprecated
了,1.24
中已经移除,因此只需要重新安装numpy
即可。
pip install 'numpy<1.24'