# 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'

# reference